df_to_csv: Convert a data.frame to a CSV-formatted character string

View source: R/df_to_csv.R

df_to_csvR Documentation

Convert a data.frame to a CSV-formatted character string

Description

The 'df_to_csv' function takes a data.frame as input and returns a character string representing the content of the original data.frame formatted as a CSV file. The resulting CSV-formatted string can be written to a file or further processed as needed.

Usage

df_to_csv(df)

Arguments

df

A data.frame to be converted to a CSV-formatted character string.

Value

A character string representing the data values in the input data.frame formatted as a CSV file.

Examples

# Create a data.frame
example_data <- data.frame(
  Name = c("Alice", "Bob", "Carol"),
  Age = c(30, 25, 28),
  Height = c(168, 175, 162),
  stringsAsFactors = FALSE
)

# Convert the data.frame to a CSV-formatted character string
csv_string <- df_to_csv(example_data)
cat(csv_string)

TheOpenAIR documentation built on April 27, 2023, 5:10 p.m.