[R] Replace NAs in a range of data frame columns

Michael Scharkow michael at underused.org
Sat Dec 12 23:52:53 CET 2009


Dear all,

I'm stuck in a seemingly trivial task that I need to perform for many
datasets. Basically, I want to replace NA with 0 in a specified range of 
columns in a dataframe. I know the first and last column to be recoded 
only by its name.

I can select the columns starting like this
a[match('first',names(a)): match('last',names(a))]

The question is how can replace all NA with 0 in this subset of the data?

Thanks and greetings,
Michael




More information about the R-help mailing list