rexceldataframecsvwrite.table

How to write a dataframe table to excel in R


I have a data frame that looks like this:

TIME      Type    A      B      C
15:15:00  Alpha   5      3      1
...       ...     ...    ...    ...

I tried: write.table(data, file="data.csv", col.names=TRUE) but it did not work. All I get is that the data for each row is completely in the first cell of each row.

The row with TIME, Type, A, B, C should be HEADER or the names of the column and separate the data down below.

Any suggestions? Thank you!


Solution

  • Try this

    install.packages("openxlsx", dependencies = TRUE)
    
    openxlsx::write.xlsx(data, "data.xlsx")