Sunday, 15 August 2010

r - How to handle conditional data.frame subscripts that contain NAs? -



r - How to handle conditional data.frame subscripts that contain NAs? -

is there way have conditional subscripts if conditional vector contains nas? assume have data.frame this

dframe <- data.frame(a=c(1,32,4,5,8),b=c(1,2,3,4,5),d=c(na,5,5,10,9)) dframe[dframe$d > 9,"a"] <- na

if not na in dframe$d straight forward. have seen %in% syntax here around nas, not know how manage conditions. can see of general problem, since not quite sure whether want obtain na missing value in status or else. interested larn how people handle situation.

in specific situation in helpful when na treated false in condition.

you can restrict indexing non na values

dframe[dframe$d > 9 & !is.na(dframe$d),"a"] <- na

r condition missing-data na

No comments:

Post a Comment