This function takes a data frame and splits it into multiple parts based on the specified number of columns. It can also include row names as a column if a valid row name label is provided.

split_df(df, num_col, return_list = FALSE)

Arguments

df

A data frame to be split.

num_col

An integer specifying the number of columns to split the data frame into.

return_list

A logical indicating whether to return a list of data frames (default: FALSE).

Value

A new data frame that is split into the specified number of columns or a list of data frames if return_list is TRUE.

Examples

split_df(mtcars[1:10, 1:3], num_col = 2, return_list = FALSE)
#>                    mpg cyl disp mpg\r cyl\r disp\r
#> Mazda RX4         21.0   6  160  18.1     6  225.0
#> Mazda RX4 Wag     21.0   6  160  14.3     8  360.0
#> Datsun 710        22.8   4  108  24.4     4  146.7
#> Hornet 4 Drive    21.4   6  258  22.8     4  140.8
#> Hornet Sportabout 18.7   8  360  19.2     6  167.6