0

I use the "tuber" library for R. In this code snippet I load a file with IDs YouTube-channels and write the information to a vector. Next step in the loop I go through the ID and paste an array element (youtube channel) as an argument to the "list_channel_videos" function. The result of the function is a list with information about the channel. How can I write information about all channels sequentially to a csv file? If I use this code, information recorded only about the last channel from the array.

vtest <- read.csv2("tester.csv", header = FALSE) arrv <- as.matrix(vtest) arv <- as.vector(arrv) iterator <- 1 for (iterator in 1:length(arv)) { nv <- list_channel_videos(channel_id = arv[iterator]) write.csv2(nv, file="bb.csv", append = TRUE) } 

2 Answers 2

1

We can use rbindlist

library(data.table) nv <- rbindlist(lapply(arv, list_channel_videos)) fwrite(nv, 'bb.csv') 
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, Thank You too. I have a new question: how i can count iterations in lapply?
0

You can use lapply and combine the output in one dataframe.

nv <- do.call(rbind, lapply(arv, list_channel_videos)) #You can also use `purrr`'s `map_df` function nv <- purrr::map_df(arv, list_channel_videos) 

Write this data together in a csv file.

write.csv2(nv, file="bb.csv") 

3 Comments

I have a new question: how i can count iterations in lapply?
@AlexeyDidorenko Can you ask that as a new question?
Just here link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.