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
4
votes
4 answers

Combining tab delim files into a single file using R

I have several txt files with 3 columns in each files like this: file 1: ProbeID X_Signal_intensity X_P-Value xxx 2.34 .89 xxx 6.45 .04 xxx 1.09 .91 xxx 5.87 .70 . …
Dinesh
  • 643
  • 5
  • 16
  • 31
4
votes
1 answer

Monitoring R data loading progress when using read.table

I've found a lot of answers for other types of data loading, but none for showing progress when R is reading data using read.table(...). I've got a simple command: data = read.table(file=filename, sep="\t", …
Hamy
  • 20,662
  • 15
  • 74
  • 102
4
votes
3 answers

Reading text file that is "next line delimited"

I'm not sure how to phrase this question correctly, so I'll give an example. Let say I have a .txt file where the first row is a DATE and the second is a TEXT. Then the pattern repeats, 3rd rows is DATE, 4th is TEXT. How would I read this into R…
jmich738
  • 1,565
  • 3
  • 24
  • 41
4
votes
1 answer

Extra commas at end of lines causing error with read.csv and read.table

I am trying to read this .csv file into R. When I use read.csv, I either get errors related to row.names, or the column names are offset from their original columns. Based on this post I believe the problem is related to having an extra comma at the…
Josh
  • 1,210
  • 12
  • 30
4
votes
1 answer

Reading large data with messy strings and multiple string indicators R

I have a large (8GB+) csv file (comma-separated) that I want to read into R. The file contains three columns date #in 2017-12-27 format text #a string type #a label per string (either NA, typeA, or typeB) The problem I encounter is that the text…
ben_aaron
  • 1,504
  • 2
  • 19
  • 39
4
votes
2 answers

Reading a zip file in R without knowing the csv file name within it

I am trying to read a zip file that has 1 csv file in it. It works great when I know the csv file name but when I just try to extract the zip file alone, it doesn't work. Here is an example of where it does works: zip_file <- abc.zip csv_file <-…
nak5120
  • 4,089
  • 4
  • 35
  • 94
4
votes
0 answers

Append a different character other than 'X' to make sytactically valid column names

When reading a csv, R automatically appends the letter X to syntactically invalid column names. For example: > read.csv(text = "a,1,b") [1] a X1 b How, can I append a different letter within the read.csv function when reading in the file, for…
pd441
  • 2,644
  • 9
  • 30
  • 41
4
votes
1 answer

Reading very small numbers in R

So I'm trying to generate some plots for my dataset, but I've encountered a certain problem with some values. Some values are very small: 1.62132528761108e-1916 small to be exact and when it's read on R, it turns into 0.00000000000e+00 I'm reading…
Pavlos Panteliadis
  • 1,495
  • 1
  • 15
  • 25
4
votes
3 answers

R read data with records sometimes on two lines

I need to read data from text files (many of them and very large), that typically look as…
mimmo970
  • 39
  • 5
4
votes
3 answers

R read.csv data from inline string with a csv file content

this is supposed to be a trivial thing, but I have not found anything googling it. I have the following data in a csv file test.csv var1,var2 'a',1 'b',2 which I read into R with d <- read.csv('test.csv') This there a way for me to insert the…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
4
votes
2 answers

Column names shift to left on read.table or read.csv

Originally I have this TSV file (sample): name type qty cxfm 1C 0 d2 H50 2 g3g 1G 2 hb E37 1 nlx E45 4 so I am using read.csv to read data from a .tsv file but I always get this output: name type qty 1…
Chayma Atallah
  • 725
  • 2
  • 13
  • 30
4
votes
3 answers

Using rbind() to combine multiple data frames into one larger data.frame within lapply()

I'm using R-Studio 0.99.491 and R version 3.2.3 (2015-12-10). I'm a relative newbie to R, and I'd appreciate some help. I'm doing a project where I'm trying to use the server logs on an old media server to identify which folders/files within the…
John Lynch
  • 75
  • 1
  • 1
  • 9
4
votes
1 answer

Reading text into data.frame where string values contain spaces

What's the easiest way to read text from a printed data.frame into a data.frame when there are string values containing spaces that interfere with read.table? For instance, this data.frame excerpt does not pose a problem: candname party…
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
4
votes
1 answer

How to read in multiple data tables into R using apply function?

I am relatively new to R and I'm having a problem reading in multiple tables from a directory using an apply function. What I would like to have the function do is to use a vector with paths to tables that I'm interested in and generate a list with…
sam
  • 41
  • 1
  • 1
  • 3
4
votes
1 answer

Reading fixed width format file in R

I'm attempting to read this fixed width file into R using read.fwf: http://www.cpc.ncep.noaa.gov/data/indices/wksst8110.for When I perform this function I'm getting some weird errors that I cannot sort out unless I read it a very specific way: > fwf…
Zach
  • 1,316
  • 2
  • 14
  • 21