CSV To R DataFrame

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert CSV to R DataFrame online — paste, edit, and download R.

DataFrame Name
Strings As Factors
Row Names
Indent
2 4 Tab
Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

CSV to R DataFrame — Free Online R Code Generator

What Is R?

R is a programming language and environment for statistical computing, data analysis, and visualization. It is widely used in statistics, bioinformatics, finance, and data science.

# R console

> x <- c(1, 2, 3, 4, 5)

> mean(x)

[1] 3

What Is an R DataFrame?

A data.frame is R's primary data structure for tabular data — similar to a spreadsheet or SQL table. Each column can hold a different data type.

df <- data.frame(

 name  = c("Alice", "Bob", "Charlie"),

 age   = c(30, 25, 35),

 city  = c("New York", "London", "Tokyo")

)

print(df)

    name age      city

1   Alice  30  New York

2     Bob  25    London

3 Charlie  35     Tokyo

DataFrame Properties

PropertyDescription
ColumnsNamed vectors, each with a single type
RowsObservations, accessed by row number or name
TypesEach column has one type (numeric, character, factor, logical)
Dimensionsnrow(df) rows × ncol(df) columns
Accessdf$column, df[1, ], df[, "name"]

read.csv() vs. This Tool

Using read.csv() (Runtime)

df <- read.csv("data.csv", stringsAsFactors = FALSE)
Aspectread.csv()
When to useDynamic CSV files at runtime
RequiresFile path or URL at runtime
FlexibilityHandles any CSV with many options
DependenciesRequires CSV file present

Using This Tool (Code Generation)

AspectThis Tool
When to useStatic data, testing, examples, tutorials
OutputSelf-contained R code
FlexibilityEditable R source code
DependenciesNone at runtime — data is literal code

Why Convert CSV to R DataFrame Code?

Use CaseDescription
R tutorialsEmbed sample datasets directly in R Markdown or tutorials
TestingCreate test data.frames for unit tests (testthat)
R MarkdownInclude data in .Rmd documents without external files
Shiny appsHardcode small datasets in Shiny applications
Data analysisPaste CSV data into R scripts as data.frame code
EducationTeach R with concrete, reproducible data examples
Package examplesCreate example datasets in R package documentation
Data cleaningUse the table editor to clean CSV before generating R code

Core Features

1. Online Table Editor

After loading CSV data, an interactive spreadsheet grid lets you edit before converting:

OperationDescription
TransposeSwap rows and columns
ClearRemove all data
Delete EmptyRemove empty rows/columns
DeduplicateRemove duplicate rows
ReplaceFind and replace (with regex support)
Case transformUPPERCASE, lowercase, Title Case
Insert/deleteRight-click for row/column operations
First Row as HeaderToggle header treatment

2. DataFrame Name

Sets the variable name for the generated data.frame:

# DataFrame Name = "employees"

employees <- data.frame(

 name = c("Alice", "Bob"),

 age  = c(30, 25)

)

Use descriptive names: sales_data, user_table, sensor_readings, survey_results.

3. Strings As Factors

Controls whether string columns are converted to factors.

R 4.0+ changed the default from TRUE to FALSE. This option ensures compatibility.

Enabled (stringsAsFactors = TRUE):

df <- data.frame(

 name = c("Alice", "Bob"),

 stringsAsFactors = TRUE

)

# name column is a factor with levels "Alice", "Bob"

class(df$name)  # "factor"

Disabled (stringsAsFactors = FALSE):

df <- data.frame(

 name = c("Alice", "Bob"),

 stringsAsFactors = FALSE

)

# name column is character

class(df$name)  # "character"

When to UseSetting
Statistical modeling (lm, glm)stringsAsFactors = TRUE — factors work with formulas
Data manipulation (dplyr, stringr)stringsAsFactors = FALSE — character is easier to work with
Compatibility with old codestringsAsFactors = TRUE — matches R < 4.0 behavior
Modern R (tidyverse)stringsAsFactors = FALSE — tidyverse prefers character

4. Row Names

Sets row names for the data.frame. Row names appear on the left side of the output.

With row names:

df <- data.frame(

 name = c("Alice", "Bob"),

 row.names = c("row1", "row2")

)

#       name

# row1 Alice

# row2   Bob

Without row names (default):

df <- data.frame(

 name = c("Alice", "Bob")

)

#     name

# 1  Alice

# 2    Bob

5. Indent

Controls code indentation:

OptionWhen to Use
2 spacesDefault — compact, readable
4 spacesDeeply nested code
TabMatch project conventions

6. Privacy

All processing runs entirely in your browser. No data is uploaded to any server.

How to Use This Tool

Step 1: Load CSV Data

Choose one of two input methods:

  • Upload a file: Click "Choose File" and select a .csv file.

  • Paste data: Click "Enter Data" to switch to the code editor. Paste your CSV.

Step 2: Edit in Table Editor (Optional)

Use the toolbar to clean your data before converting.

Step 3: Configure R Output

Use the Properties panel:

  1. DataFrame Name: Enter a variable name (e.g., sales_data).

  2. Strings As Factors: Enable for statistical modeling; disable for tidyverse.

  3. Row Names: Optionally set row names.

  4. Indent: Choose formatting.

Step 4: Convert

Click Convert. The R code appears in the "Output Data" panel.

Step 5: Copy or Download

  • Click Copy to Clipboard to paste into your .R or .Rmd file.

  • Premium users can click Download File to save.

Complete Example

Example — Employee Data

Input CSV:

name,department,salary,active

Alice,Engineering,95000,true

Bob,Marketing,78000,false

Charlie,Engineering,102000,true

Diana,Design,85000,true

Configuration:

  • DataFrame Name: employees

  • Strings As Factors: FALSE

  • Row Names: (none)

  • Indent: 2 spaces

Output:

employees <- data.frame(

 name        = c("Alice", "Bob", "Charlie", "Diana"),

 department  = c("Engineering", "Marketing", "Engineering", "Design"),

 salary      = c(95000, 78000, 102000, 85000),

 active      = c("true", "false", "true", "true"),

 stringsAsFactors = FALSE

)

Example — Statistical Modeling (Factors Enabled)

Input CSV:

species,petal_length,petal_width

setosa,1.4,0.2

setosa,1.3,0.2

versicolor,4.7,1.4

versicolor,4.5,1.5

virginica,6.0,2.5

virginica,5.9,2.1

Configuration: Strings As Factors: TRUE

Output:

iris_data <- data.frame(

 species      = c("setosa", "setosa", "versicolor", "versicolor", "virginica", "virginica"),

 petal_length = c(1.4, 1.3, 4.7, 4.5, 6.0, 5.9),

 petal_width  = c(0.2, 0.2, 1.4, 1.5, 2.5, 2.1),

 stringsAsFactors = TRUE

)

# Now fit a linear model

model <- lm(petal_width ~ petal_length + species, data = iris_data)

summary(model)

Example — Tidyverse Workflow

Input CSV:

product,price,stock

Laptop,1299.99,45

Phone,699.99,120

Tablet,499.99,0

Configuration: Strings As Factors: FALSE

After converting, use with dplyr:

library(dplyr)products <- data.frame(

 product = c("Laptop", "Phone", "Tablet"),

 price   = c(1299.99, 699.99, 499.99),

 stock   = c(45, 120, 0),

 stringsAsFactors = FALSE

)

products %>%

 filter(stock > 0) %>%

 mutate(value = price * stock) %>%

 arrange(desc(value))

CSV-to-R Type Mapping

CSV ValueR TypeExample
"hello"characterc("hello", "world")
42numericc(42, 100)
3.14numericc(3.14, 2.72)
TRUE / FALSEcharacter (from CSV)c("TRUE", "FALSE")
Empty cellNANA

Note: CSV values are all text. The tool outputs character vectors. Convert types in R:

df$age <- as.integer(df$age)

df$price <- as.numeric(df$price)

df$active <- as.logical(df$active)

Common R DataFrame Operations

# Basic info

nrow(df)              # Number of rows

ncol(df)              # Number of columns

colnames(df)          # Column names

str(df)               # Structure

summary(df)           # Statistical summary

head(df)              # First 6 rows


# Access

df$column_name        # Column as vector

df[1, ]               # First row

df[, "name"]          # Column by name

df[df$age > 28, ]     # Filter rows


# Modify

df$new_col <- df$a + df$b       # Add column

df$name <- tolower(df$name)     # Transform column

df <- df[order(df$age), ]       # Sort


# Export

write.csv(df, "output.csv", row.names = FALSE)

Frequently Asked Questions (FAQ)

  • Does the tool upload my data?

    No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.

  • What is an R data.frame?

    A data.frame is R's primary tabular data structure. It stores data in rows and columns where each column has a single data type. It is similar to a spreadsheet or SQL table.

  • What is stringsAsFactors?

    stringsAsFactors controls whether string columns become factors (categorical data). In R 4.0+, the default is FALSE (character). Enable for statistical modeling with lm() or glm(); disable for tidyverse data manipulation.

  • What is the difference between character and factor?

    Character is plain text — easy to manipulate with stringr and dplyr. Factor is a categorical variable with fixed levels — required by many R modeling functions (lm, glm, aov). Factors use less memory for repeated values.

  • Can I use the output in R Markdown?

    Yes. Paste the generated code directly into an R Markdown .Rmd code chunk. The data.frame will be created when the document is knitted.

  • What is the difference between this tool and read.csv()?

    read.csv() reads CSV files at runtime. This tool generates R source code that creates a data.frame from literal values. Use this tool for static data, tutorials, and examples; use read.csv() for dynamic data.

  • Can I edit the data before converting?

    Yes. The built-in table editor lets you modify cells, transpose, deduplicate, find/replace, change case, and insert/delete rows and columns.

  • What CSV formats are supported?

    Standard CSV with comma delimiters. The first row can be used as column headers (enable "First Row as Header").

  • Is there a file size limit?

    The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.

  • Can I use this on mobile?

    Yes. The tool is responsive, though the table editor is best experienced on desktop.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online CSV to JSONLines (NDJSON) converter. Transform CSV or TSV into newline-delimited JSON objects or arrays. Supports smart JSON parsing and formatting. 100% client-side.

CSV To JSONLines

Free online CSV to JSONLines (NDJSON) converter. Transform CSV or TSV into newline-delimited JSON objects or arrays. Supports smart JSON parsing and formatting. 100% client-side.
Free online CSV to LaTeX table converter. Import CSV or TSV, customize alignment, borders, captions, and float position, then export publication-ready LaTeX code. 100% client-side.

CSV To LaTeX Table

Free online CSV to LaTeX table converter. Import CSV or TSV, customize alignment, borders, captions, and float position, then export publication-ready LaTeX code. 100% client-side.
Free online CSV to custom template converter. Transform CSV or TSV data into SQL, JSON, XML, Markdown, or any custom format using template syntax. 100% client-side — your data stays on your device.

CSV To Custom Template

Free online CSV to custom template converter. Transform CSV or TSV data into SQL, JSON, XML, Markdown, or any custom format using template syntax. 100% client-side — your data stays on your device.
Free online CSV to Markdown table converter with 7 formatting options and table editor. Escape chars, alignment, bold headers, pretty/simple format. 100% client-side.

CSV To Markdown Table

Free online CSV to Markdown table converter with 7 formatting options and table editor. Escape chars, alignment, bold headers, pretty/simple format. 100% client-side.