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

Barber, Eric eric.barber at convergys.com
Thu Mar 28 11:30:22 CET 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list