-1

I need to convert multiple columns (all of the values in each column) in a data frame to have NA as their value, is this possible in R?

Phil
  • 7,287
  • 3
  • 36
  • 66
Gab
  • 11

1 Answers1

0

You may assign NA to multiple columns. Example:

mtcars[c("mpg", "cyl", "disp")] <- NA
head(mtcars)
#                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4          NA  NA   NA 110 3.90 2.620 16.46  0  1    4    4
# Mazda RX4 Wag      NA  NA   NA 110 3.90 2.875 17.02  0  1    4    4
# Datsun 710         NA  NA   NA  93 3.85 2.320 18.61  1  1    4    1
# Hornet 4 Drive     NA  NA   NA 110 3.08 3.215 19.44  1  0    3    1
# Hornet Sportabout  NA  NA   NA 175 3.15 3.440 17.02  0  0    3    2
# Valiant            NA  NA   NA 105 2.76 3.460 20.22  1  0    3    1
jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • Thank you so much! I had a feeling it was a simple answer but for some reason everything I found was showing me how to replace NA! – Gab Sep 06 '22 at 16:06