There is a dataframe
named cnbd
, for example:
cnbd = data.frame(1,2,3,NA,NA,5)
Thus the expression:
dim(cnbd)[1]
give 1.
I want to write a dataframe like cnbd
to a csv with:
write(file = filename, cnbd, append = TRUE)
The problem comes:
cnbd
with 6 rows not 1 row as 1,2,3,NA,NA,5
.cnbd
show as 1,2,3,,,5
in csv file, no NAs.Use write. csv() to export R DataFrame to CSV file with fields separated by comma delimiter, header (column names), rows index, and values surrounded with double-quotes. You can also override this default behavior and export CSV without header, without row index or number, with no quotes e.t.c.
Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file object to write the CSV data into a file. Otherwise, the CSV data is returned in the string format.
Try this:
write.table(df, "cnbd.csv", na = "", row.names = FALSE, col.names = FALSE, append = TRUE, sep = ",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With