rw_r2019
rw_r2019

Reputation: 23

Read in part of .csv file

I am trying to read in a .csv file into R. The first 12 rows of the csv contain background information that is not needed, but is in two columns. The rest of the data is from row 13 and is in 10 columns. Is it possible to read in the file from row 13, as using read.csv normally puts the file in 2 columns and ruins it? thanks in advance

Upvotes: 2

Views: 514

Answers (2)

Will M
Will M

Reputation: 812

Say you want to read in rows 13 to 20 and your csv. file is separated by ";":

data <- read.csv("filename.csv", sep = ";", row.names=c(13:20), col_names = c("firstcolname", "secondcolname", "thirdcolname", ..., "tenthcolname"))

Upvotes: 0

Kris
Kris

Reputation: 420

This should be relatively straightforward with read.csv().

try this:

data <- read.csv(file = "yourdirectory/yourfile.csv", skip = 12, header = FALSE)

Note: setting header = FALSE makes sure that the first line reads in as data rather than as column labels. If these are actually column labels, change to header = TRUE.

Upvotes: 1

Related Questions