export list as csv in r

To export a list as a CSV file in R, you can use the write.csv() function. Here's an example:

main.r
# create a toy list
my_list <- list(names = c("Alice", "Bob", "Charlie"),
                ages = c(25, 30, 35),
                colors = c("red", "green", "blue"))

# write the list to a CSV file
write.csv(my_list, file = "my_list.csv")
237 chars
8 lines

In this example, we first create a list called my_list that contains three vectors: names, ages, and colors. We then use the write.csv() function to write this list to a CSV file called "my_list.csv".

Note that the resulting CSV file will have each vector of the list as a separate column, and the row names of the list will become the first column of the CSV file.

gistlibby LogSnag