dataframe - Replace all NA with FALSE in selected columns in R -
I have a question, but my dataset is slightly larger: 50 columns with 1 column as UID and other columns To move either Can Thanks for the quick response, but if my dataset is as below: How can I do this, to process only If you want to substitute for a subset of variables, you still have TRUE or NA , I want to change all NA to FALSE , but I do not Wants to use clear loop. plyr do the trick? Thank you. UPDATE # 1
df < - data.frame (id = C (delegate (1:19), NA), X1 = sample (C (NA, true), 20, space = TRUE), x2 = sample (C, NA, TRUE) , Replaced = TRUE)) X1 and X2 ? is .na (*) & lt; - moves as follows:
df [c ("x1", "x2")] [is.na (df [c ("x1", "x2" ) The IMO makes the logic easy to use the temporary variable:
vars.to.replace & lt; - c ("X1", "x2") df2 & lt; - df [Vars.to.replace] df2 [is.na (df2)] <- FALSE df [vars.to.replace]
Comments
Post a Comment