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
Post a Comment