r - how to write function within function to save objects as separated csv file? -


i have function follows:

v2_city <-          function(city_name){                 result <- v2[city == city_name]                 result } 

v2_city dataset has columns of "city_name", "offers". create filter function save filtered data separated objects , save them csv file.

to so, created city names in list , wanted use loop follows:

list <- c( 'osaka' ,'paris' ,'roma' ,'barcelona' ,'fukuoka' ,'hong kong')  (item in list){         x <- v2[item] } 

this gives x file filtered hongkong. how save separate files objects , write them csv within loop?

how about?

library(dplyr) library(readr)  my_dataset = tibble(city = c("osaka","paris","roma","barcelona","fukuoka","hong kong"), value = 1:6)  cities = c("osaka","paris","roma","barcelona","fukuoka","hong kong")  (j in 1:length(cities){   my_dataset %>%      filter(city == cities[[j]]) %>%      write_csv(paste0(cities[[j]],".csv")) } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -