r - Recode a subset of column and row -
i have data.frame , want recode specific column after selecting row value. data.frame this. first column id, second , third columns value use select specific rows, column 4 , above value store want recode.
i have store column name want recode in vector -> list1
df <- data.frame(letters[1:10],letters[1:2],letters[3:4],rep(0:1,each=5),rep(1:0,each=5),rep(1:0,each=5),rep(1:0,each=5)) names(df)<-c("sample","cond1","cond2","ge1","ge2","ge3","ge4") df list1 <- c("ge1","ge3")
what want get: when select cond1 == , cond2 == c can recode value of specific column (listed in vector) in case column ge1 , ge3.
a.e if conditions meet ge1 , ge3 recode na.
i have tried things : df$cond1[df$cond1 == "a" & df$cond2 =="c"]
, many other fail!
you're wanting set conditional rows of specific columns na
?
df[df$cond1=="a" & df$cond2=="c", list1] <- na
Comments
Post a Comment