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 TRUE or NA , I want to change all NA to FALSE , but I do not Wants to use clear loop.

Can plyr do the trick? Thank you.

UPDATE # 1

Thanks for the quick response, but if my dataset is as below:

  df < - data.frame (id = C (delegate (1:19), NA), X1 = sample (C (NA, true), 20, space = TRUE), x2 = sample (C, NA, TRUE) , Replaced = TRUE))   

How can I do this, to process only X1 and X2 ?

If you want to substitute for a subset of variables, you still have 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

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -