On 6/12/2006 8:48 AM, Arun Kumar Saha wrote:
> Dear all R users,
>
> I am wondering whether there is any way to replace all "NA" values in a data
> frame by some numerical value, suppose 1000?
In a vector it is easy, e.g. x[is.na(x)] <- 1000. A dataframe is a list
of vectors, so you could iterate through the list, using one of the
apply functions (or even a for loop):
apply(x, 2, function(col) {col[is.na(col)] <- 1000; col} )
which is essentially a short form for
for (i in 1:ncol(x)) {
col <- x[,i]
col[is.na(col)] <- 1000
x[,i] <- col
}
Duncan Murdoch
>
> Thanks and Regards
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html