r - How can I attach new levels with specific values for specific rows -


i have dataframe column name of individuals , columns results. want attach new column either 1 , 2 or na depending on individual.

i have vector individuals level 1 , 1 individuals level 2

how can attach collumn data frame goes this: if dataframe$individual (1,3,6,7) value in column 1, if dataframe$individual (2,5,8) value in column 2, else value na

i hope made clear example looking for. help

try

dat$newcol <- with(dat, ifelse(individual %in% c(1,3,6,7), 1,                       ifelse(individual %in% c(2,5,8), 2, na))) 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -