Re: [R] sapply again return value
Hi, A simple way is: s - s[3] On 16/02/07, Antje [EMAIL PROTECTED] wrote: Hello, I used an sapply to get some data back (s - sapply(...) ). The output of s would then deliver something like this: B06_lamp.csv C06_lamp.csv D06_lamp.csv [1,] NULL NULL Numeric,512 [2,] NULL NULL Numeric,512 [3,] NULL NULL 2 mode(s) [1] list dim(s) [1] 3 3 Now, I'd like to remove the columns which contain NULL (it's alway the whole column). How can I do this??? Antje __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-ParanĂ¡ Brasil [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sapply again return value
Henrique Dallazuanna schrieb: Hi, A simple way is: s - s[3] but what if I don't know how many and which columns are NULL? Antje __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sapply again return value
Antje niederlein-rstat at yahoo.de writes: Hello, I used an sapply to get some data back (s - sapply(...) ). The output of s would then deliver something like this: B06_lamp.csv C06_lamp.csv D06_lamp.csv [1,] NULL NULL Numeric,512 [2,] NULL NULL Numeric,512 [3,] NULL NULL 2 mode(s) [1] list dim(s) [1] 3 3 Now, I'd like to remove the columns which contain NULL (it's alway the whole column). How can I do this??? Antje As long as it is always the whole column, you can just test the first row, like this: s-matrix(list(NULL,NULL,NULL,NULL,NULL,NULL,numeric(512),numeric (512),2),ncol=3) s[,!apply(s,2,sapply,is.null)[1,],drop=FALSE] [,1] [1,] Numeric,512 [2,] Numeric,512 [3,] 2 If you would like to make sure that the whole column is NULL, you could do something like the following: s[,!apply(apply(s,2,sapply,is.null),2,sum)==nrow(s),drop=FALSE] [,1] [1,] Numeric,512 [2,] Numeric,512 [3,] 2 I use the drop=FALSE here for display purposes, but you may want to leave it off depending on desired format. Mark __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.