0

I'm new to R and I have to run Fleiss's kappa on over a thousand pre-made dataframes. I know how it's done individually:

kappam.fleiss(df1, exact=TRUE)

But I have to run the same test across every dataframe:

kappam.fleiss(df1, exact=TRUE)
kappam.fleiss(df2, exact=TRUE)
kappam.fleiss(df3, exact=TRUE)
...
...
kappam.fleiss(df5166, exact=TRUE)

I'm having some trouble phrasing my question correctly, but all I've found so far seem to be loops and functions which don't rightly work when I'm trying to combine dataframes - c(df1, df2, df3, ..., df5166)

Anyone can point me in the right direction?

alistaire
  • 42,459
  • 4
  • 77
  • 117
  • You hopefully realize that exact tests are not any kind of magic wand that prevents the Multiple Comparisons Dragon from blowing flames all over this effort and turning it into ashes? – IRTFM Nov 20 '18 at 03:07
  • canonical "lists of data frames" answer: https://stackoverflow.com/a/24376207/4497050 – alistaire Nov 20 '18 at 04:52

1 Answers1

1

We place the datasets in a list and apply the function

out <- lapply(mget(paste0("df", 1:5166)), kappm.fleiss, exact = TRUE)

NOTE: It is unusual to have these many objects loaded in the global environment. A better option would be to not create any objects globally, instead create a single list by loading the files into the list (if the dataset objects are read from a folder)

akrun
  • 874,273
  • 37
  • 540
  • 662
  • Would there be an alternative, for the above if the data frames are not given nice names? Instead of df1, df2, ..., df50, I have df1, ab2, ru6, etc? – LifeOne Nov 20 '18 at 04:35
  • @LifeOne If there are no patterns and these are the only objects loaded inthe global env, then `mget(ls())` – akrun Nov 20 '18 at 05:16