I have a list of data.frames> str(bins)List of 19217 $ 100026:'data.frame': 1 obs. of 6 variables: ..$ Sku : chr "100026" ..$ Bin : chr "T149C" ..$ Count: int 108 ..$ X : int 20 ..$ Y : int 149 ..$ Z : chr "3" $ 100030:'data.frame': 1 obs. of 6 variables: ....... As you can see one 'column' is "Count". This list seems to contain 19217 data.frames. I would like to create an array of 19217 integers which hold the values of the "Count" column. I have tried the obvious (to me): bins[[1:3]]$Count But that returns NULL instead of an array of length 3 that I was expecting. Interestingly bins[[1]]$Count returns the first "Count" in the list of data frames. How do I get all of the "Count"s? Thank you. Kevin
On Fri, 2009-04-03 at 11:45 -0700, rkevinburton at charter.net wrote:> I have a list of data.frames > > > str(bins) > > List of 19217 > $ 100026:'data.frame': 1 obs. of 6 variables: > ..$ Sku : chr "100026" > ..$ Bin : chr "T149C" > ..$ Count: int 108 > ..$ X : int 20 > ..$ Y : int 149 > ..$ Z : chr "3" > $ 100030:'data.frame': 1 obs. of 6 variables: > ....... > As you can see one 'column' is "Count". This list seems to contain 19217 data.frames. I would like to create an array of 19217 integers which hold the values of the "Count" column. I have tried the obvious (to me): > > bins[[1:3]]$Countsapply(bins, `[[`, "Count") will get you this as a vector. HTH G> But that returns NULL instead of an array of length 3 that I was > expecting. Interestingly bins[[1]]$Count returns the first "Count" in > the list of data frames. How do I get all of the "Count"s? > > Thank you. > > Kevin > > ______________________________________________ > R-help at 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090403/afd2d8d6/attachment-0002.bin>
I do not think that the form [[1:3]] is legit. > ltest <- list( "a", "b", "c", "d") > ltest[[1:3]] Error in ltest[[1:3]] : recursive indexing failed at level 2 You might try with single brackets: > ltest[1:3] [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" -- David Winsemius On Apr 3, 2009, at 2:45 PM, <rkevinburton at charter.net> wrote:> I have a list of data.frames > >> str(bins) > > List of 19217 > $ 100026:'data.frame': 1 obs. of 6 variables: > ..$ Sku : chr "100026" > ..$ Bin : chr "T149C" > ..$ Count: int 108 > ..$ X : int 20 > ..$ Y : int 149 > ..$ Z : chr "3" > $ 100030:'data.frame': 1 obs. of 6 variables: > ....... > As you can see one 'column' is "Count". This list seems to contain > 19217 data.frames. I would like to create an array of 19217 integers > which hold the values of the "Count" column. I have tried the > obvious (to me): > > bins[[1:3]]$Count > > But that returns NULL instead of an array of length 3 that I was > expecting. Interestingly bins[[1]]$Count returns the first "Count" > in the list of data frames. How do I get all of the "Count"s? > > Thank you. > > Kevin
On Fri, Apr 3, 2009 at 1:45 PM, <rkevinburton at charter.net> wrote:> I have a list of data.frames > >> str(bins) > > List of 19217 > ?$ 100026:'data.frame': 1 obs. of ?6 variables: > ?..$ Sku ?: chr "100026" > ?..$ Bin ?: chr "T149C" > ?..$ Count: int 108 > ?..$ X ? ?: int 20 > ?..$ Y ? ?: int 149 > ?..$ Z ? ?: chr "3" > ?$ 100030:'data.frame': 1 obs. of ?6 variables: > ....... > As you can see one 'column' is "Count". This list seems to contain 19217 data.frames. I would like to create an array of 19217 integers which hold the values of the "Count" column. I have tried the obvious (to me): > > bins[[1:3]]$Count > > But that returns NULL instead of an array of length 3 that I was expecting. Interestingly bins[[1]]$Count returns the first "Count" in the list of data frames. How do I get all of the "Count"s?Why not turn your list of data frames into a single data frame? bindf <- do.call("rbind", bins) bindf$Count Hadley -- http://had.co.nz/