0

I am trying to quantify the number of occurrences of elements in each of a list of column vectors. I have created the following list:

ExpYearsLists <- list(ExpYears1[,95],ExpYears2[,95],ExpYears3[,95],ExpYears4[,95],ExpYears5[,95],ExpYears6[,95],ExpYears7[,95],ExpYears8[,95],ExpYears9[,95],ExpYears10[,95],ExpYears11[,95],ExpYears12[,95],ExpYears13[,95],ExpYears14[,95],ExpYears15[,95],ExpYears16[,95],ExpYears17[,95],ExpYears18[,95],ExpYears19[,95],ExpYears20[,95],ExpYears21[,95],ExpYears22[,95],ExpYears23[,95],ExpYears24[,95],ExpYears25[,95],ExpYears26[,95],ExpYears27[,95],ExpYears28[,95],ExpYears29[,95],ExpYears30[,95],ExpYears31[,95],ExpYears32[,95],ExpYears33[,95],ExpYears34[,95],ExpYears35[,95],ExpYears36[,95],ExpYears37[,95],ExpYears38[,95],ExpYears39[,95],ExpYears40[,95],ExpYears41[,95],ExpYears42[,95],ExpYears43[,95],ExpYears44[,95],ExpYears45[,95],ExpYears46[,95],ExpYears47[,95],ExpYears48[,95],ExpYears49[,95])

and a for loop:

for (L in ExpYearsLists) {
  assign(paste("ExpYearsT", L, sep=""), data.frame(table(L)))
}

however, when I run the for loop, it creates empty data frames and throws a warning message saying that "only the first element is used as variable name." When I run an individual command such as

ExpT1 <- data.frame(table(ExpYears1[,95]))

however (which my understanding is exactly what the for loop should be doing every iteration), it creates exactly what I want. How can I make the for loop work?

yuliaUU
  • 1,581
  • 2
  • 12
  • 33
  • furthermore, if I run the a for-loop ```for (L in ExpYearsLists) { + print(data.frame(table(L)))``` the console prints each of the data frames that I am looking for – Max Nurko Sep 08 '22 at 20:15
  • 1
    It would be best if you can provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that replicates your issue. – Bushidov Sep 09 '22 at 05:19

0 Answers0