Hello,
I'm learning functions in R using tidyverse.
I want to filter and export results to a CSV file.
Here is the code:
library(tidyverse)
library(gapminder)
rm(list=ls())
datos<-gapminder::gapminder
unique_continents<-datos %>% distinct(continent) %>% pull() %>% as_vector()
example1 <- function(x) {
continent_data <- datos %>%
filter(continent == x)
return(continent_data)
filename <- paste0(x, ".csv")
write_csv2(continent_data, file = filename, row.names = FALSE)
}
example1("Americas")
map(unique_continents,example2)
When I run the code using map(... I noticed on console that I slice the data as I wanted.
But the function doesn't export any CSV file.
What am I doing wrong?
It's very simple, but at the end I failed.
Thanks for your time and interest.
Have a nice week, community.