To write data to a CSV file in R, you can use the write_csv
function from the readr
package. Here's an example:
main.r231 chars11 lines
This code creates a data frame called my_df
, which contains three columns (name
, age
, and profession
). The write_csv
function is then used to write the data frame to a CSV file called my_data.csv
.
If you want to write data to an existing CSV file, you can use the write_csv2
function instead of write_csv
. This function is identical to write_csv
, but uses a semicolon (;
) as the field separator instead of a comma.
main.r251 chars11 lines
In this code, the write_csv2
function is used to write the data frame to an existing CSV file called my_existing_data.csv
. The original contents of the file will be overwritten.
gistlibby LogSnag