Displaying 1 result from an estimated 1 matches for "iscol".
Did you mean:
icol
2004 Sep 15
5
replacing NA's with 0 in a dataframe for specified columns
I know that there must be a cool way of doing this, but I can't think
of it. Let's say I have an dataframe with NA's.
> x <- data.frame(a = c(0,1,2,NA), b = c(0,NA,1,2), c = c(NA, 0, 1, 2))
> x
a b c
1 0 0 NA
2 1 NA 0
3 2 1 1
4 NA 2 2
>
I know it is easy to replace all the NA's with zeroes.
> x[is.na(x)] <- 0
> x
a b c
1 0 0 0
2 1 0 0
3 2 1