how to extract columns in R to make multiple data frames?

theamateurdataanalyst

I need help with a simple task. I have a dataframe 28x52 and I want to make several dataframes and rename each one. So it'll turn into 13 28x4 data frames. I know this probably involves a for loop and so I tried:

for(i in seq(1,52,4)){
  i <- data[,i:i+3]
} 

It didn't work though.

A5C1D2H2I1M1N2O1R2T1

Here's one approach on a 3x9 source data.frame where we want to subset it into 3 3x3 data.frames.

m <- data.frame(matrix(1:27, ncol = 9))
lapply(split(sequence(ncol(m)), rep(1:3, each = 3)), function(x) m[, x])
# $`1`
#   X1 X2 X3
# 1  1  4  7
# 2  2  5  8
# 3  3  6  9
# 
# $`2`
#   X4 X5 X6
# 1 10 13 16
# 2 11 14 17
# 3 12 15 18
# 
# $`3`
#   X7 X8 X9
# 1 19 22 25
# 2 20 23 26
# 3 21 24 27

Create a sequence of the columns you want to extract, and create a list of your data.frames.

So, applied to something that replicates the structure of your data, you could use:

m <- data.frame(matrix(1:(28*52), ncol = 52))
lapply(split(sequence(ncol(m)), rep(1:(52/4), each = 4)), function(x) m[, x])

Collected from the Internet

Please contact debug[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

merge multiple data.frames [r]

From Java

R loop through columns in list of data frames

From Dev

Same function over multiple data frames in R

From Dev

how to extract columns in R to make multiple data frames?

From Dev

Intersecting multiple columns between two data frames

From Dev

Extract columns with same names from multiple data frames [R]

From Dev

Combining multiple data frames with different number of columns

From Dev

R - subtracting multiple columns from multiple columns with 2 data frames

From Dev

How to read multiple .xlsx and generate multimple data frames in R?

From Dev

Need to merge multiple data frames by multiple common columns

From Dev

R: Merge two data frames by common columns

From Dev

Using a loop to create multiple data frames in R

From Dev

How to merge multiple data.frames and sum and average columns at the same time in R

From Dev

R: Subset list of data frames by number of columns?

From Dev

How to compare two data frames/tables and extract data in R?

From Dev

How can I convert the format of columns from multiple data frames?

From Dev

How to change multiple columns' data type in R?

From Dev

How to calculate mean and Sd for multiple data frames in R

From Dev

Need to merge multiple data frames by multiple common columns

From Dev

how to extract two columns of data using R by loop

From Dev

Search multiple fields in two data Frames in R

From Dev

stacked bar chart in r for multiple data frames

From Dev

how to create data frames in r

From Dev

How to compute the mean of data frames columns that are not aligned in R

From Dev

Outer join 2 data frames by multiple columns in R

From Dev

R manipulating multiple data frames using a lapply

From Dev

Naming variables in multiple data frames in R

From Dev

Removing specific columns from multiple data frames (.tab) and then merging them in R

From Dev

How to merge data frames in R using *alternative* columns

Related Related

  1. 1

    merge multiple data.frames [r]

  2. 2

    R loop through columns in list of data frames

  3. 3

    Same function over multiple data frames in R

  4. 4

    how to extract columns in R to make multiple data frames?

  5. 5

    Intersecting multiple columns between two data frames

  6. 6

    Extract columns with same names from multiple data frames [R]

  7. 7

    Combining multiple data frames with different number of columns

  8. 8

    R - subtracting multiple columns from multiple columns with 2 data frames

  9. 9

    How to read multiple .xlsx and generate multimple data frames in R?

  10. 10

    Need to merge multiple data frames by multiple common columns

  11. 11

    R: Merge two data frames by common columns

  12. 12

    Using a loop to create multiple data frames in R

  13. 13

    How to merge multiple data.frames and sum and average columns at the same time in R

  14. 14

    R: Subset list of data frames by number of columns?

  15. 15

    How to compare two data frames/tables and extract data in R?

  16. 16

    How can I convert the format of columns from multiple data frames?

  17. 17

    How to change multiple columns' data type in R?

  18. 18

    How to calculate mean and Sd for multiple data frames in R

  19. 19

    Need to merge multiple data frames by multiple common columns

  20. 20

    how to extract two columns of data using R by loop

  21. 21

    Search multiple fields in two data Frames in R

  22. 22

    stacked bar chart in r for multiple data frames

  23. 23

    how to create data frames in r

  24. 24

    How to compute the mean of data frames columns that are not aligned in R

  25. 25

    Outer join 2 data frames by multiple columns in R

  26. 26

    R manipulating multiple data frames using a lapply

  27. 27

    Naming variables in multiple data frames in R

  28. 28

    Removing specific columns from multiple data frames (.tab) and then merging them in R

  29. 29

    How to merge data frames in R using *alternative* columns

HotTag

Archive