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
0
votes
1 answer

How to use read.table for file with delimiter \t

I want to read a data file using: ds <- read.table(file="/data/ken/tmp/tt", header=F, sep="\t", quote="\"", dec=".", fill=T, comment.char="", stringsAsFactors=F, …
catchyoulater
  • 89
  • 2
  • 4
0
votes
1 answer

How to build a system() function call to sed with escape characters?

I can't get this to work. I want to replace all two character occurences in the first field of a csv file with the occurence and an X appended, and whitespace removed. For example SA and SA should map to SAX in the new file. Below is what I tried…
Yoda
  • 397
  • 5
  • 18
0
votes
2 answers

Import datasets in which some columns have strings that contain spaces

I have a dataset that looks like the one below: ID Message 1 . 2 . 3 Click_screen 4 Blank screen 5 . 6 . 7 . The actual dataset has 48…
Alex
  • 4,030
  • 8
  • 40
  • 62
0
votes
1 answer

Specify column classes when reading in data via lapply(FileList, read.xls)

My question is about how to specify the class for various columns when reading in data that come from many files. More specifically, I am uploading 1000s of .xlsx files at a time and converting them to .csv files using the read.xls() function in…
Jota
  • 17,281
  • 7
  • 63
  • 93
0
votes
2 answers

R: read.table problems

I might just be crazy but I really can't see where I am going wrong on my simple R program. I am trying to read a table from a file but every time I try to it comes back with this error: ./tmp.r: line 1: syntax error near unexpected token…
Stephopolis
  • 1,765
  • 9
  • 36
  • 65
-1
votes
1 answer

Meta data .gz file in r won't load properly

The file here: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE104323 called: GSE104323_metadata_barcodes_24185cells.txt.gz Will not load properly in R, it is missing the age column which is arguably the most important metadata and half the…
Angus Campbell
  • 563
  • 4
  • 19
-1
votes
1 answer

R: Using read.table to import a column with a different delimiter than other columns?

I have a txt file of chess games from http://chess-research-project.readthedocs.io/en/latest/. The first 8 lines of the file are as follows: # # # datetime 2013-08-10 22:32:16.640552 # program…
ZhouW
  • 1,187
  • 3
  • 16
  • 39
-1
votes
1 answer

Why does R think my imported vector of characters are numbers?

This is probably a basic question, but why does R think my vector, which has a bunch of words in it, are numbers when I try to use these vectors as column names? I imported a data set and it turns out the first row of data are the column headers…
user6472523
  • 211
  • 3
  • 8
-1
votes
2 answers

Issues reading data as csv in R

I have a large data set of (~20000x1). Not all the fields are filled, in other words the data does have missing values. Each feature is a string. I have done the following code runs: Input: data <- read.csv("data.csv", header=TRUE, quote = "") datan…
-1
votes
2 answers

Importing fread vs read.table and errors

When I import a .csv file with read.table, with the call df <- read.table("ModelSugar(new) real_thesis_experiment-table_1.csv", skip = 6, sep = ",", head = TRUE) and I check the summary of the data I get (only first 3 columns of 45 are shown): …
Marijn
  • 61
  • 1
  • 7
-1
votes
2 answers

Extract data after a string one each appearance R

I have a data like this (named spectra): #Milk spectra: 1234 ##XYDATA=(X++(Y..Y)) 649.025085449219 667.675231457819 686.325377466418 ##XYDATA=(X++(Y..Y)) 723.625669483618 742.275815492218 760.925961500818 ##XYDATA=(X++(Y..Y)) 872.826837552417…
hn.phuong
  • 835
  • 6
  • 15
  • 24
-1
votes
2 answers

Error In fill in read.table in R

I am trying to import the data from the CSV file. The code I used is below New <- read.table("New.csv", fill="TRUE") and below is the CSV file data: Name Sex Age Score Aspirations Rhea F 18 98 Doctor John M 17 90 Engineer Rads …
-1
votes
1 answer

Custom column design

I have a raw dataset and the columns are not clearly defined at all. When I go to import the data using "Read.Table" in R, it automatically tries to approximate where the columns begin and end. But it is not correct. I know the number of characters…
SharpSharpLes
  • 302
  • 4
  • 20
-1
votes
1 answer

Name variable according to Function input in R

I am trying to perform the following: Analyse_Store <- function("x"){ datapaste"x" <- read.table(file = "x".txt, sep=";", header = TRUE) } So basically I am trying to read a table named "x" and assign it to the name datapaste"x" unfortunately…
Raphael
  • 116
  • 7
-1
votes
1 answer

Error using read.table due to colCLasses

I'm trying to import a CSV using read.table. Since specifying colClasses makes it faster, I tried to use it (it works without colCLasses, so I definitely know this is the issue). The following is the error I got: Error in scan(file, what, nmax, sep,…
SB3891
  • 61
  • 8
1 2 3
37
38