Skip to content
Prev 55754 / 398500 Next

replacing NA's with 0 in a dataframe for specified columns

Dear David,

How about the following?

cols <- c(1,3)
x[,cols][is.na(x[,cols])] <- 0

I hope that this helps,
 John

On Wed, 15 Sep 2004 14:44:53 -0400
David Kane <dave at kanecap.com> wrote:
--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/