How to apply write_fst() function to each dataframe in list?

274 Views Asked by At

I want to save each dataframe from list with its according names as .fst file. My list with dataframes is called tables. I tried to do this, but it didn't work:

lapply(write_fst(), tables)

How to do that? How to perform write_fst function to each dataframe in list?

2

There are 2 best solutions below

0
On BEST ANSWER

You can try using Map -

Map(write_fst, tables, names(tables))

If the names of the list do not have extension (.fst) you can use paste0 to add it.

Map(write_fst, tables, paste0(names(tables), '.fst'))
0
On

You can loop through a list of data.frames:

require(fst)

l = list(
  iris = iris,
  mtcars = mtcars,
  airquality = airquality
)

for (i in seq_along(l)) {
  write_fst(l[[i]], path = paste0(names(l)[i], '.fst'))
}