Questions tagged [read.table]

read.table is basic R function which reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file.

read.table is basic R function which reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file. It is the most convenient way to read in a rectangular grid of data.

Because of the many possibilities, there are several other functions that call read.table but change a group of default arguments. Convenience functions read.csv and read.delim provide arguments to read.table appropriate for CSV and tab-delimited files exported from spreadsheets in English-speaking locales. The variations read.csv2 and read.delim2 are appropriate for use in those locales where the comma is used for the decimal point and (for read.csv2) for spreadsheets which use semicolons to separate fields.

See also The R Data Import/Export manual.

567 questions
10
votes
3 answers

Difference between read.table and read.delim functions

What is the difference between the read.table() and read.delim() functions in the R language?
user1021713
  • 2,133
  • 8
  • 27
  • 40
9
votes
2 answers

read.fwf and the number sign

I am trying to read this file (3.8mb) using its fixed-width structure as described in the following link. This command: a <- read.fwf('~/ccsl.txt',c(2,30,6,2,30,8,10,11,6,8)) Produces an error: line 37 did not have 10 elements After replicating…
Alex
  • 222
  • 1
  • 9
8
votes
1 answer

length of 'dimnames' [2] not equal to array extent when using corrplot function from a matrix read from a csv file

I wanna read the data from a csv file, save it as a matrix and use it for visualization. data<-read.table("Desktop/Decision_Tree/cor_test_.csv",header = F,sep = ",") data V1 V2 V3 V4 V5 V6 1 1.00 0.00 0.00 0.00 0.00 0 2 0.11 …
Jeffrey Chen
  • 81
  • 1
  • 1
  • 2
8
votes
1 answer

Read table with comment lines starting with "##"

I'm struggling to read my tables in Variant Call Format (VCF) with R. Each file has some comment lines starting with ##, and then the header starting with #. ## contig= ## contig= #CHROM POS ID REF ALT…
Slavskii Sergei
  • 138
  • 1
  • 9
8
votes
3 answers

Append\Union two or several tables into one

I input 5 text data sets into R using read.table. Each data set has the same structure (100 rows, 50 cols). I would like to union\append all the five tables together into one table, which will be 500 rows * 50 cols. Anyone know how to do that?
qqqwww
  • 521
  • 1
  • 10
  • 19
8
votes
1 answer

Specifying multi-character comment tokens in R's read.table()

Is it somehow possible to specify a comment character in R that consists of more than 1 symbol? for example, read.table("data.dat", comment.char="//") won't work.
user2015601
8
votes
1 answer

Reading in a file - Warning Message

I have a file that has 22268 rows BY 2521 columns. When I try to read in the file using this line of code: file <- read.table(textfile, skip=2, header=TRUE, sep="\t", fill=TRUE, blank.lines.skip=FALSE) But I only get 13024 rows BY 2521 columns read…
Sheila
  • 2,438
  • 7
  • 28
  • 37
7
votes
1 answer

Can you specify the number of columns in read.table?

I am trying to automate the reading in of files generated from another analysis program. The standard output is typically in 6 columns separated by spaces with a carriage return at the end. This reads in nicely by simply using "strip.white = TRUE"…
N Brouwer
  • 4,778
  • 7
  • 30
  • 35
7
votes
1 answer

R 3.5 - read.csv not able to read UTF-16 csv file

My code is as follows: read.csv("http://asic.gov.au/Reports/YTD/2018/RR20180420-001-SSDailyYTD.csv", skip=1, fileEncoding = "UTF-16", sep = "\t", header = FALSE) R 3.4.3 - Code executes cleanly R 3.5.0 - gives the following error: Error in…
cephalopod
  • 1,826
  • 22
  • 31
7
votes
1 answer

Import txt file in R ignoring first few lines

downloaded data from the MET office on rainfall for Scotland. First few lines: Scotland Rainfall (mm) Areal series, starting from 1910 Allowances have been made for topographic, coastal and urban effects where relationships are found to…
Shery
  • 1,808
  • 5
  • 27
  • 51
7
votes
2 answers

Skip empty files when importing text files

I have a folder with about 700 text files that I want to import and add a column to. I've figured out how to do this using the following code: files = list.files(pattern = "*c.txt") DF <- NULL for (f in files) { data <- read.table(f, header = F,…
wallflower
  • 437
  • 1
  • 5
  • 9
7
votes
1 answer

R read.csv how to ignore carriage return?

I need to read a text file (tab-separated) that has some carriage returns inside some fields. If I use read.table, it gives me an error: line 6257 did not have 20 elements If I use read.csv, it doesn't give an error, but creates a new line in that…
Rodrigo
  • 4,706
  • 6
  • 51
  • 94
7
votes
2 answers

read.csv Read Specific Row

How can we read specific rows into R using the read.csv command? Say if I have a CSV file which has 10 rows of data, and I just want to only read the 5th row of data, I tried doing the following but it doesn't seem to be working: myFile <-…
Outrigger
  • 149
  • 1
  • 3
  • 10
6
votes
1 answer

column names have periods inserted where there should be spaces

In the plot generated by ggplot, each label along the x-axis is a string, i.e., “the product in 1990”. However, the generated plot there is a period in between each word. In other words, the above string is shown as “the.product.in.1990” How can I…
bit-question
  • 3,733
  • 17
  • 50
  • 63
6
votes
3 answers

read.delim() - errors "more columns than column names" and "header and ''col.names" are of different lengths"

Preliminary information OS: Windows XP Professional Version 2002 Service Pack 3; R version: R 2.12.2 (2011-02-25) I am attempting to read a 30,000 row by 80 column, tab-delimited text file into R using the read.delim() function. This file does have…
Jubbles
  • 4,450
  • 8
  • 35
  • 47
1 2
3
37 38