Hi, One problem with your example dataset is that you have 11 list elements with the last one having different dimensions. I think it was based on `summarized`. Then, the second problem I encountered for testing is that the dataset you provided doesn't fulfill the criteria. lst1<- list(structure(list......) #output of dput lst2<- lst1[1:10] #deleted the last list element lst3<-lapply(lst2,function(x) {x$V3<- as.character(x$V3);x}) #here if I apply one of the conditions, none of the list elements fulfill the criteria #for example lapply(lst3,function(x) subset(x,V1==6 & V6>300 & V6<3000,select="V6")) #[1]] #[1] V6 #<0 rows> (or 0-length row.names) # #[[2]] #[1] V6 #<0 rows> (or 0-length row.names) # #[[3]] #[1] V6 #<0 rows> (or 0-length row.names) ---------------------------------------------
#changed the V1 column set.seed(24) lst4<- lapply(lst3,function(x) {x$V1<- sample(c(0,3,6),nrow(x),replace=TRUE);x}) #I am skipping the first 2, ie. 'id' and 'iat.date' as the filenames were not provided. res<-t(sapply(lst4,function(x) {block4<-x[with(x,V1==3 & V6>300 & V6<3000),"V6"];block7<- x[with(x,V1==6 & V6>300 & V6<3000),"V6"];block4.m<- mean(block4);block7.m<- mean(block7);block4.sd<-sd(block4);block7.sd<- sd(block7);full<- x[with(x,(V1==3|V1==6) & (V6 >300) & (V6 <3000)),"V6"];full.sd<- sd(full);diff1<-block7.m-block4.m;d<- diff1/full.sd; c(block4.m,block4.sd,block7.m,block7.sd,diff1,full.sd,d) })) colnames(res)<- c("block4.m","block4.sd","block7.m","block7.sd","diff1","full.sd","d") Hope this helps. A.K. Hi, I downloaded a psychological test off of github and it came with a code for R to write the data into a .csv file. When I type the following: for(i in 1:length(data.list)) { filename = strsplit(output.files[i],'-') id = filename[[1]][2] iat.date = paste(filename[[1]][4],"-",filename[[1]][5],"-",filename[[1]][3]," ",filename[[1]][6],":",substr(filename[[1]][7],1,2),sep="") block4.m = mean(subset(data.list[[i]], V1==3 & V6>300 & V6 < 3000, select="V6")) block7.m = mean(subset(data.list[[i]], V1==6 & V6>300 & V6 < 3000, select="V6")) block4.sd = sd(subset(data.list[[i]], V1==3 & V6>300 & V6 < 3000, select="V6")) block7.sd = sd(subset(data.list[[i]], V1==6 & V6>300 & V6 < 3000, select="V6")) full.sd = sd(subset(data.list[[i]], (V1==6 | V1==3) & V6>300 & V6 < 3000, select="V6")) diff = block7.m - block4.m d = diff / full.sd summarized[i,] = c(id, iat.date, block4.m, block4.sd, block7.m, block7.sd, diff, full.sd, d) } I get the following errors/warnings: Error in is.data.frame(x) : (list) object cannot be coerced to type 'double' In addition: Warning messages: 1: In mean.default(subset(data.list[[i]], V1 == 3 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 2: In mean.default(subset(data.list[[i]], V1 == 6 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 3: In mean.default(subset(data.list[[i]], V1 == 3 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 4: In mean.default(subset(data.list[[i]], V1 == 6 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 5: In mean.default(subset(data.list[[i]], V1 == 3 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 6: In mean.default(subset(data.list[[i]], V1 == 6 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 7: In mean.default(subset(data.list[[i]], V1 == 3 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA 8: In mean.default(subset(data.list[[i]], V1 == 6 & V6 > 300 & V6 < : argument is not numeric or logical: returning NA Would anyone be able to help me with this problem? I am relatively new to R, so I cannot seem to recognize exactly what the problem is. Thanks so much! list(structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 4L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 4L, 2L, 4L, 2L, 2L, 4L, 4L, 2L, 2L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(2L, 5L, 2L, 1L, 2L, 5L, 4L, 5L, 1L, 5L, 4L, 3L, 4L, 0L, 2L, 3L, 1L, 3L, 5L, 0L), V5 = c(1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), V6 = c(598L, 95L, 142L, 83L, 143L, 167L, 32L, 129L, 31L, 136L, 2L, 142L, 23L, 160L, 105L, 144L, 64L, 152L, 71L, 129L )), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 4L, 2L, 4L, 2L, 4L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(2L, 1L, 4L, 1L, 4L, 2L, 0L, 2L, 4L, 1L, 2L, 3L, 2L, 1L, 3L, 0L, 4L, 1L, 4L, 1L ), V5 = c(1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L), V6 = c(878L, 145L, 112L, 104L, 112L, 96L, 112L, 168L, 192L, 112L, 192L, 200L, 200L, 199L, 32L, 201L, 176L, 200L, 224L, 120L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list( V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(4L, 4L, 2L, 2L, 4L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 4L, 2L, 2L, 2L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(5L, 2L, 1L, 3L, 1L, 0L, 1L, 5L, 1L, 3L, 2L, 3L, 4L, 0L, 4L, 2L, 4L, 0L, 5L, 0L), V5 = c(0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L), V6 = c(830L, 295L, 136L, 696L, 136L, 80L, 183L, 176L, 192L, 184L, 176L, 176L, 184L, 72L, 120L, 96L, 207L, 112L, 192L, 216L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(4L, 2L, 2L, 4L, 2L, 4L, 2L, 2L, 4L, 2L, 4L, 4L, 2L, 2L, 4L, 4L, 4L, 2L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(3L, 1L, 3L, 2L, 0L, 2L, 1L, 3L, 2L, 1L, 4L, 0L, 1L, 2L, 4L, 2L, 3L, 4L, 1L, 2L ), V5 = c(0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L), V6 = c(1831L, 536L, 760L, 472L, 752L, 503L, 576L, 839L, 767L, 257L, 80L, 223L, 120L, 175L, 96L, 200L, 192L, 103L, 119L, 191L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 4L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 4L, 2L, 4L, 2L, 2L, 4L, 4L, 4L, 2L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(0L, 2L, 1L, 4L, 3L, 2L, 4L, 2L, 0L, 2L, 4L, 3L, 5L, 0L, 5L, 4L, 2L, 0L, 4L, 1L), V5 = c(1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L), V6 = c(775L, 1648L, 303L, 160L, 296L, 272L, 72L, 184L, 80L, 232L, 184L, 88L, 160L, 231L, 88L, 224L, 232L, 152L, 72L, 256L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 4L, 2L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 4L, 2L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(4L, 2L, 4L, 3L, 1L, 4L, 3L, 0L, 3L, 2L, 3L, 4L, 0L, 3L, 4L, 3L, 2L, 1L, 3L, 0L), V5 = c(1L, 1L, 1L, 1L, 0L, 1L, 1L, 2L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L), V6 = c(991L, 312L, 271L, 409L, 176L, 280L, 360L, 735L, 248L, 208L, 152L, 167L, 295L, 159L, 393L, 199L, 135L, 257L, 151L, 112L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(4L, 4L, 2L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 4L, 4L, 4L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(0L, 2L, 4L, 0L, 2L, 0L, 3L, 2L, 3L, 0L, 2L, 3L, 1L, 0L, 4L, 1L, 4L, 1L, 3L, 1L), V5 = c(0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 2L, 1L), V6 = c(3367L, 631L, 159L, 193L, 176L, 192L, 127L, 176L, 73L, 176L, 183L, 200L, 183L, 152L, 40L, 135L, 183L, 191L, 199L, 215L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 2L, 4L, 4L, 4L, 2L, 4L, 2L, 4L, 4L, 2L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 2L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(1L, 4L, 1L, 3L, 1L, 2L, 1L, 3L, 4L, 2L, 4L, 0L, 3L, 0L, 2L, 1L, 0L, 1L, 3L, 1L), V5 = c(1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L), V6 = c(566L, 263L, 80L, 247L, 280L, 143L, 104L, 103L, 137L, 192L, 65L, 136L, 39L, 216L, 240L, 231L, 215L, 239L, 128L, 88L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 2L, 4L, 2L, 4L, 4L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 4L, 2L, 4L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(4L, 3L, 2L, 1L, 3L, 0L, 3L, 4L, 1L, 4L, 0L, 4L, 0L, 3L, 4L, 1L, 0L, 2L, 1L, 3L), V5 = c(1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L), V6 = c(1910L, 311L, 272L, 96L, 328L, 376L, 159L, 352L, 1929L, 728L, 535L, 679L, 552L, 896L, 711L, 688L, 768L, 768L, 983L, 688L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), V2 = 0:19, V3 = structure(c(2L, 4L, 2L, 4L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 2L, 2L, 2L, 4L, 4L, 2L, 4L, 4L), .Label = c("NEG", "NON", "POS", "SUI"), class = "factor"), V4 = c(4L, 0L, 3L, 4L, 0L, 1L, 3L, 2L, 0L, 4L, 3L, 2L, 1L, 3L, 2L, 1L, 0L, 4L, 2L, 3L), V5 = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L), V6 = c(654L, 152L, 23L, 185L, 160L, 72L, 135L, 184L, 183L, 112L, 94L, 106L, 96L, 200L, 200L, 135L, 201L, 55L, 144L, 176L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, 20L), class = "data.frame"), structure(list(V1 = c(NA, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), V2 = structure(c(1L, 2L, 2L, 2L, NA, NA, NA, NA, NA, NA, NA, NA), .Label = c("Id", "related"), class = "factor"), V3 = structure(c(4L, 1L, 2L, 3L, NA, NA, NA, NA, NA, NA, NA, NA), .Label = c("2013-06-999999 25:03", "2013-06-99999as5pt 27:22", "2013-06-99999bJ1Td 25:19", "Date"), class = "factor"), V4 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "Block4.m", class = "factor"), V5 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "Block4.sd", class = "factor"), V6 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "Block7.m", class = "factor"), V7 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "Block7.sd", class = "factor"), V8 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "diff", class = "factor"), V9 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "full.sd", class = "factor"), V10 = structure(c(1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Label = "d", class = "factor")), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10"), row.names = c(NA, 12L), class = "data.frame")) ______________________________________________ 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.