1. No comment on original garbled HTML code. 2. Comment on: "... Within your last statement it appears you are trying to find the sum of a logical vector - is.na(). This is what is causing the error."
That is false: > sum(rep(c(FALSE,TRUE),3)) [1] 3 Please do read basic R documents -- this is about automatic coercion -- before dispensing false advice. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Tue, Nov 11, 2014 at 7:42 AM, Mark Sharp <msh...@txbiomed.org> wrote: > Aditya, > > Please use plan text. HTML is not handled correctly. > > Within your last statement it appears you are trying to find the sum of a > logical vector - is.na(). This is what is causing the error. > > My guess is that you want to count the number of elements in the second > column that are not NA values. You probably want the following for your last > line. (See ?sum). > > nummk <- length(vbm[ !is.na(vbm[ , 2], 2]) > ## or > nummk <- nrow(vbm[!is.na(vbm[ , 2], ]) > > ## The is.na(vbm[ ,2]) returns a logical vector (for example c(FALSE, TRUE, > TRUE)) > > Mark > > R. Mark Sharp, Ph.D. > Director Primate Records Database > Southwest National Primate Research Center > Director of Scientific Computing > Texas Biomedical Research Institute > P.O. Box 760549 > San Antonio, TX 78245-0549 > Office telephone: (210)258-9476 (is forwarded to mobile telephone; message > are captured into e-mail.) > Mobile telephone: (210) 218-2868 > > > > > On Nov 11, 2014, at 3:05 AM, Aditya Singh wrote: > > setwd("C:/Documents and > Settings/Administrator/Desktop/Coursera/specdata/specdata")temp=list.files(pattern="*.csv")myfiles=lapply(temp,read.delim)summk=0nummk=0for > (i in 1:10) { vb=data.frame(myfiles[i]) vbm=as.double(vb) > summk=sum(vbm[,2]) nummk=length(vbm[,2]) - sum(is.na(vbm[,2]))} > Aditya > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org<mailto:R-help@r-project.org> 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. > > > ________________________________ > NOTICE: This E-Mail (including attachments) is confidential and may be > legally privileged. It is covered by the Electronic Communications Privacy > Act, 18 U.S.C.2510-2521. If you are not the intended recipient, you are > hereby notified that any retention, dissemination, distribution or copying of > this communication is strictly prohibited. Please reply to the sender that > you have received this message in error, then delete it. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. ______________________________________________ R-help@r-project.org 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.