I have a for loop that assigns multiple data frames in different values and it works by itself. But when I try to create a function with this for loop, it doesn't work. On top of assigning different names to different data frames, I'm also trying to create a vector that keeps the names of these dataframes, but seems like this function doesn't save "dfnames"
create_df <- function(name){
dfnames <- c()
for(i in name){
assign(paste0("subject", i, sep = "_"), passive_subject(i))
dfnames <- c(dfnames, paste0("subject", i, sep = "_"))
dfnames
}
}
How can I go about this?
passive_subjectassignfor something like this. Use a list instead. See dww's answer.subject_nobjects are not in a list and are separate from the collection of their names. It's not surprising that you are not getting what you want. You shoudl be creating a list with names, rather than a bunch of separate objects and a separate naming vector. You should change the checkmark to award @dww