I'm clustering using kmeans, and it doesn't accept NA. if NA occurs in a column of the data frame, it occurs in every column, including column 1. they say that a (good) programmer can write FORTRAN in any language, so I came up with this, where tbl is the data frame containing NA -> newtbl<-NULL > for (i in 1:length(tbl)){if (!is.na(tbl[1,i])){+ newtbl<-if (is.null(newtbl))data.frame(tbl[i]) else data.frame(newtbl,tbl[i])}}>however, from looking at the examples in the reference manual, I believe that the same effect could be achieved using a more concise, APL-like, syntax. offers? thanks, Eric -- Eric Barber <eric.barber at convergys.com> +44 1223 48 8132 Geneva Product Unit, Convergys, Block 3, Westbrook Centre, Milton Road, Cambridge CB4 1YS, England NOTICE: The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect/reverse charges), so that the sender's address records can be corrected. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Mar-28 10:40 UTC
[R] extracting non-NA columns from a data frame
On Thu, 28 Mar 2002, Barber, Eric wrote:> I'm clustering using kmeans, and it doesn't accept NA. if NA occurs in a > column of the data frame, it occurs in every column, including column 1. > they say that a (good) programmer can write FORTRAN in any language, so I > came up with this, where tbl is the data frame containing NA - > > newtbl<-NULL > > for (i in 1:length(tbl)){if (!is.na(tbl[1,i])){ > + newtbl<-if (is.null(newtbl))data.frame(tbl[i]) else > data.frame(newtbl,tbl[i])}} > > > however, from looking at the examples in the reference manual, I believe > that the same effect could be achieved using a more concise, APL-like, > syntax. offers??na.omit -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._