There are few post related to this question but none could help me to solve it. for example How to split a data frame? How to split a data frame into multiple data frames based on columns
What I want is to split the data based on different column number, for example 1, then I must have as many columns as a data frame has. 2, I must have half of a data frame data (if it is even)
An example data is below
fredTable <- structure(list(Symbol = structure(c(3L, 1L, 4L, 2L, 5L), .Label = c("CASACBM027SBOG",
"FRPACBW027SBOG", "TLAACBM027SBOG", "TOTBKCR", "USNIM"), class = "factor"),
Name = structure(1:5, .Label = c("bankAssets", "bankCash",
"bankCredWk", "bankFFRRPWk", "bankIntMargQtr"), class = "factor"),
Category = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Banks", class = "factor"),
Country = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "USA", class = "factor"),
Lead = structure(c(1L, 1L, 3L, 3L, 2L), .Label = c("Monthly",
"Quarterly", "Weekly"), class = "factor"), Freq = structure(c(2L,
1L, 3L, 3L, 4L), .Label = c("1947-01-01", "1973-01-01", "1973-01-03",
"1984-01-01"), class = "factor"), Start = structure(c(1L,
1L, 1L, 1L, 1L), .Label = "Current", class = "factor"), End = c(TRUE,
TRUE, TRUE, TRUE, FALSE), SeasAdj = c(FALSE, FALSE, FALSE,
FALSE, TRUE), Percent = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Fed", class = "factor"),
Source = structure(c(1L, 1L, 1L, 1L, 1L), .Label = "Res", class = "factor"),
Series = structure(c(1L, 1L, 1L, 1L, 2L), .Label = c("Level",
"Ratio"), class = "factor")), .Names = c("Symbol", "Name",
"Category", "Country", "Lead", "Freq", "Start", "End", "SeasAdj",
"Percent", "Source", "Series"), row.names = c("1", "2", "3",
"4", "5"), class = "data.frame")
I want to split it to 12 data frames and name them case 1 to 12.
so my first data frame is case1
case_1
TLAACBM027SBOG
CASACBM027SBOG
TOTBKCR
FRPACBW027SBOG
USNIM
the second data frame is case 2
case_2
bankAssets
bankCash
bankCredWk
bankFFRRPWk
bankIntMargQtr
etc.
In case I set the number to 2, i should have 6 columns (pairs of 2) with name as cas_1, case_2 until case_12
I know that split function is used to split the data but I could not figure out how to do it
for first case I did like
split(fredTable, 1:ncol(fredTable))