I am trying to apply a loop to extract vectors from dataframe columns. But failing. Can anyone help me
> df <- data.frame(sym = c("ABC","CGF","DFG"))
> com_list <- c(1:3)
for (j in com_list)
{
com <- c()
com <- c(com[j], paste0(df$sym[j], collapse=","))
}
> com
[1] "DFG"
Expected output
> com
"ABC,CGF,DFG"
com <- paste0(df$sym, collapse = ',')