0

As the subject suggests, I'm trying to write a list of data frames into a new folder so, that the original name stays same as the original file (and so that the original files don't get overwritten in the original folder!). Tried the code below, but simply didn't get the syntax working:

sapply(names(points_calculated), 
       function (x) write_csv(points_calculated[[x]], file=paste("./ExperimentFolder/PointsFolder", x)))

1 Answer 1

2

Given that points_calculated is a list of data.frames, and the names(points_calculated) are the filename you want, you can do the following:

library(purrr)
points_calculated %>%
  iwalk(
    ~ readr::write_csv(.x, file = paste("./ExperimentFolder/PointsFolder", .y))
  )
)

imap() will iterate over your list, and perform the function after ~. .x is the element of the list (the data.frame), and .y is it's name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.