How do I reorder columns for all data frames in a list in R?

Viewed 1267

I already have a list of data frames (mylist) and need to switch the first and second column for all the data frames in the list.

Test Data Frame in List

[reads] [phylum]
1         phylum1
2         phylum2
3         phylum3

Into....

[phylum] [reads]
phylum1      1
phylum2      2
phylum3      3

I know I need to use lapply, but not sure what to input for the FUN=

mylist <- lapply(mylist, FUN = mylist[ ,c("phylum", "reads")])

errors saying incorrect number of dimensions

Sorry if this is a simple question and thanks in advance for your help!

-Brand new R user

1 Answers
Related