[R] how to remove NaN columns ?
Liaw, Andy
andy_liaw at merck.com
Fri Oct 24 19:55:13 CEST 2003
As an example:
> dat <- data.frame(x=1:5, y=NaN, z=5:1)
> dat
x y z
1 1 NaN 5
2 2 NaN 4
3 3 NaN 3
4 4 NaN 2
5 5 NaN 1
> bad <- sapply(dat, function(x) all(is.nan(x)))
> dat[,!bad]
x z
1 1 5
2 2 4
3 3 3
4 4 2
5 5 1
HTH,
Andy
> -----Original Message-----
> From: ryszard.czerminski at pharma.novartis.com
> [mailto:ryszard.czerminski at pharma.novartis.com]
> Sent: Friday, October 24, 2003 1:46 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] how to remove NaN columns ?
>
>
> How can I remove columns with NaN entries ?
>
> Here is my simple example:
>
> > data <- read.csv("test.csv")
> > xdata <- data[3:length(data)]
> > xs <- lapply(xdata, function(x){(x - mean(x))/sqrt(var(x))}) x <-
> > data.frame(xs) x
> C D E F
> 1 -0.7071068 NaN -0.7071068 -0.7071068
> 2 0.7071068 NaN 0.7071068 0.7071068
>
> I am sure it is possible to remove column D (with NaN's) in
> some simple
> fashion, using is.nan function
> without explicitly looping through, and I am sure I was able
> to do it in
> the past, but I cannot recall how.
>
> Your help will be greatly appreciated.
>
> Ryszard
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>
More information about the R-help
mailing list