[R] Error: (list) object cannot be coerced to type double; on running the following code in R ver 3.1.2

Mark Sharp msharp at txbiomed.org
Tue Nov 11 16:42:35 CET 2014


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))


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]))}

[[alternative HTML version deleted]]

R-help at r-project.org<mailto:R-help at r-project.org> mailing list
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]]

More information about the R-help mailing list