r - How to create a factor variable from values from two other columns -


i want add new categorical variable based on values 2 other columns.

in example below, want create new variable "simple" using semester , gender info.

 semester gender score simple   01       f       152    f_01  02       m       190    m_02 

can dplyr? cheers

in tidyr, there unite concatenate columns

library(tidyr) school_info %>%         unite(simple, gender, semester, remove=false) #   simple semester gender score #1   f_01       01      f   152 #2   m_02       02      m   190 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -