[R] extracting non-NA columns from a data frame

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Mar 28 11:40:42 CET 2002

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?


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

More information about the R-help mailing list