The fwrite() function from data.table package is used to write data frame or data table in a file.

The following method shows how you can do it with syntax.

Method: Use fwrite() Function


fwrite(df,"File name")

The following example shows how to use fwrite() function in R.

Use fwrite() Function to Write Data Frame in File

Let’s see how we can write data frame in CSV file.

# Import library

# Create data frame
df <- data.frame(Machine_name=c("A","B","C","D","E","F"),
                 Pressure=c(78.2, 71.7, 80.21, 83.12, 82.56, 79.50),
                 Temperature=c(31, 35, 36, 36, 38, 32))

# Export data frame to CSV file
fwrite(df, file='sample.csv')

In the above code we write data frame to sample.csv file using fwrite() function.