dataframe - R Data Table: How to combine a list of data frame into single Data table -
i have following list of data frames. want combine them , store result in data table
a <- data.frame(a=1:3) b <- data.frame(b=4:6) ab_list <- list(a,b)
one of ways achieve
ab_df <- data.table(do.call("cbind", ab_list))
is there other way directly result, without wrapping explicitly
if have data frames in list, as.data.table
work. see example.
require(data.table) ab_list <- lapply(seq(letters), function(i) { df <- data.frame(a = (3*i-2):(3*i)) names(df) <- letters[i] df }) as.data.table(ab_list)
to list of data frames need vector of data frame names using ls()
, argument pattern
or grep()
. after can create list of data frames.
df_names <- letters df_list <- mget(df_names)
Comments
Post a Comment