0
votes

so here is my problem: I have some code that extracts some data from 29 excel files and organizes anything labelled "sw" into one variable, and everything labeled "rep" into another variable:

file.number <- c(1:29)
data <-setNames(lapply(paste0(file.number,".csv"),read.csv,stringsAsFactors=FALSE),paste0(file.number,".data"))
n <- 1:29
df <- data.frame(RT=1:100,rep.sw=sample(c("sw","rep",100,replace=TRUE)))
sw <- lapply(data[n],function(df) with(df,na.omit(RT[rep.sw=="sw"])))  
rep <- lapply(data[n],function(df) with(df,na.omit(RT[rep.sw=="rep"])))

I want to then find out the means and standard deviations of these files, except when I used mean(sw) it tells me that "argument is not numerical or logical: returning NA". if I open "sw" or "rep" I get something like this:

$28.data [1] 0.8476 0.8362 0.5442 0.6987 0.7859 0.7396 1.0230 1.2446 0.8683 0.6049 0.6355 0.7421 0.9611 [14] 0.8074 0.9847 0.6291 1.0054 0.6969 0.7265 0.6452 0.7258 0.8099 0.6202 0.7873 0.6800 0.6932 [27] 1.4137 0.9585 1.6352 0.5182 0.9112 0.6410 0.7425 0.8477 0.6520 0.7538 1.0690 0.4945 0.6436 [40] 0.3885 0.6794 0.7635 0.7180 0.4817 0.6300 0.7036 0.6592 0.5893 0.7757 0.7562 0.9872 1.2523 [53] 0.6881 0.9567 1.2612 0.6691 1.0147 0.7342 0.5541 0.7812 0.8366 0.6086 0.3273 2.7230 1.1746 [66] 0.6796 0.5465 0.7613 0.7385 0.7043 0.6008 0.5958 1.1628 0.6029 0.6236 0.6968 0.9634 0.4779 [79] 0.7606 0.9773 0.7741 0.5647 0.8278 0.5899 0.5874 0.7234 0.5261 0.5980 0.5951 attr(,"na.action") [1] 1 3 4 5 7 9 10 12 14 16 18 20 22 24 26 27 29 31 33 35 37 39 41 [24] 42 44 46 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 [47] 86 88 90 92 94 95 97 99 101 102 103 105 107 109 111 112 114 116 118 119 121 123 125 [70] 126 128 130 132 134 135 136 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 [93] 169 171 173 174 176 178 179 181 183 185 187 189 191 193 195 attr(,"class") [1] "omit"

$29.data [1] 0.6426 0.5946 0.6903 0.6798 0.7299 0.8263 0.6023 0.6095 0.5822 0.7946 0.5403 0.5716 0.6120 [14] 0.6508 0.5124 0.4831 0.5197 0.5750 0.5578 0.5993 0.7203 0.5777 0.5906 0.4900 0.5620 0.7961 [27] 0.5908 0.6904 0.5560 0.4818 0.4990 0.5240 0.5225 0.6483 0.6777 0.4982 0.6693 0.6540 0.5528 [40] 0.5033 0.5314 0.5208 0.5375 0.6032 0.5255 0.5439 0.4703 0.5123 0.6321 0.5057 0.5668 0.5387 [53] 0.5980 0.5555 0.5745 0.5961 0.5186 0.5541 0.5976 0.9179 0.6375 0.5769 0.5807 0.6663 0.6177 [66] 0.5507 0.4639 0.8702 0.5002 0.5325 0.4975 0.5741 0.5051 0.5476 0.8307 0.4861 0.6348 0.5990 [79] 0.5649 0.6674 0.5247 0.4840 0.5376 0.5241 0.6764 0.5281 0.6310 0.6082 0.5833 0.5424 0.5984 [92] 0.6329 attr(,"na.action") [1] 1 3 5 7 9 11 12 14 16 18 20 21 23 24 25 27 28 30 32 34 36 38 39 [24] 41 43 45 47 49 50 52 53 54 56 58 60 62 63 65 67 69 70 72 73 74 76 78 [47] 79 81 82 84 85 87 89 91 93 95 97 99 101 102 104 106 108 109 111 112 114 116 118 [70] 120 122 123 125 127 129 131 133 135 137 139 141 143 145 146 148 150 152 153 155 157 159 161 [93] 163 164 166 167 168 170 172 174 175 177 179 180 182 184 186 187 189 191 193 195 197 199 201 [116] 203 205 206 208 210 212 213 attr(,"class") [1] "omit"

Any help will be greatly, greatly appreciated!

1

1 Answers

2
votes

Your sw and rep objects are list objects and so you cannot directly use mean on them.

If you want the mean of each component of the list, you can:

    sapply(sw,mean)