export csv in dataframe in r

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

main.r
# create a sample dataframe
df <- data.frame(name = c("John", "Mary", "Peter"), age = c(25, 30, 35), salary = c(50000, 60000, 70000))

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

In this example, we first create a sample dataframe called df. We then use the write.csv() function to export df to a file called my_data.csv. The row.names = FALSE argument specifies that the row names of df should not be included in the exported file.

related categories

gistlibby LogSnag