export a dataframe as csv file in r

To export a dataframe as a CSV file in R, you can use the write.csv() function.

Here is an example code block that exports a dataframe named my_data to a CSV file named my_data.csv:

# create a dataframe
my_data <- data.frame(
  name = c("John", "Jane", "Bob", "Sue"),
  age = c(25, 30, 35, 40),
  city = c("New York", "Paris", "London", "Sydney")
)

# export the dataframe to a CSV file
write.csv(my_data, "my_data.csv", row.names = FALSE)
258 chars
10 lines

In this example, we first create a dataframe called my_data with some sample data. Then, we use the write.csv() function to export the dataframe to a CSV file named my_data.csv. The row.names = FALSE argument ensures that the row names of the dataframe are not included in the exported file.

gistlibby LogSnag