read.table

Converting text file into data frame in R

旧街凉风 提交于 2019-12-01 11:13:53
My raw data is in a text file with no particular delimiters between the values, like so: 101 10.08 S A 05OCT93 GOLDEN GATE BRIDGE 4110 6548 6404 55930 Applying read.table in R creates a data frame with only one variable per row, whereas I would like a data frame with 10 variables per row (one for each of the 10 values). How can I achieve this if there is no delimiter in the text file? We assume that each field consist of non-spaces except for field 6 which may have embedded spaces. Create test file Lines <- "101 10.08 S A 05OCT93 GOLDEN GATE BRIDGE 4110 6548 6404 55930 101 10.08 S A 05OCT93

Error in read.table: !header: invalid argument type

本小妞迷上赌 提交于 2019-12-01 08:47:51
I am having the strangest of issues. The following code no longer works: Test<-matrix(rnorm(9),ncol=3) colnames(Test)<-c("a","b","c") write.table(Test,file="Test.txt") d<-read.table("Test.txt",header=T) I get: Error in !header: invalid argument type I tried rebooting R, it didn't help. Check class(T) . Most likely T was overwritten with a non-boolean value. Restart of R probably loads the saved session. 来源: https://stackoverflow.com/questions/21775169/error-in-read-table-header-invalid-argument-type

Converting text file into data frame in R

白昼怎懂夜的黑 提交于 2019-12-01 07:34:09
问题 My raw data is in a text file with no particular delimiters between the values, like so: 101 10.08 S A 05OCT93 GOLDEN GATE BRIDGE 4110 6548 6404 55930 Applying read.table in R creates a data frame with only one variable per row, whereas I would like a data frame with 10 variables per row (one for each of the 10 values). How can I achieve this if there is no delimiter in the text file? 回答1: We assume that each field consist of non-spaces except for field 6 which may have embedded spaces.

Read.table while using '#' as delimiter does not work?

孤人 提交于 2019-12-01 07:11:11
I have a data file with the # sign as delimiter, that I would like to read with the read.file command. First of all; it's a big data file and I don't want to change the delimiter because: the risk of using a different delimiter that already exists in the data (note: can be checked, but point 2 makes this a little bit more complicated) I expect more of these data files with all the # sign as delimiter, so I don't want to change the data files every time when I would like to read a these files again So I assumed I could use the sep argument of the read.file command. But it didn't worked out for

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

醉酒当歌 提交于 2019-12-01 06:29:17
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 objects consisting of each data frame corresponding the paths in that file. I've written the following code: f<- function(directory){ file.list <<- list.files(directory) file.paths <<- as.vector(paste(directory, file.list, sep = "/")) tables <- lapply(X = file.paths, FUN = read.table, header = TRUE,sep = "\t" )) } By my understanding, what I'm doing

Read.table while using '#' as delimiter does not work?

纵饮孤独 提交于 2019-12-01 04:49:23
问题 I have a data file with the # sign as delimiter, that I would like to read with the read.file command. First of all; it's a big data file and I don't want to change the delimiter because: the risk of using a different delimiter that already exists in the data (note: can be checked, but point 2 makes this a little bit more complicated) I expect more of these data files with all the # sign as delimiter, so I don't want to change the data files every time when I would like to read a these files

What does the “More Columns than Column Names” error mean?

巧了我就是萌 提交于 2019-12-01 02:36:54
I'm trying to read in a .csv file from the IRS and it doesn't appear to be formatted in any weird way. I'm using the read.table() function, which I have used several times in the past but it isn't working this time; instead, I get this error: data_0910<-read.table("/Users/blahblahblah/countyinflow0910.csv",header=T,stringsAsFactors=FALSE,colClasses="character") Error in read.table("/Users/blahblahblah/countyinflow0910.csv", : more columns than column names Why is it doing this? For reference, the .csv files can be found at: http://www.irs.gov/uac/SOI-Tax-Stats-County-to-County-Migration-Data

Combining tab delim files into a single file using R

做~自己de王妃 提交于 2019-11-30 22:00:55
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 . . . . . . . . . file 2: ProbeID Y_Signal_intensity Y_P-Value xxx 1.4 .92 xxx 2.55 .14 xxx 4.19 .16 xxx 3.47 .80 . . . . . . . . . file 3: ProbeID Z_Signal_intensity Z_P-Value xxx 9.40 .82 xxx 1.55 .04 xxx 3.19 .56 xxx 2.47 .90 . . . . . . . . . In all the above files the values of ProbeID column are identical but not the other columns.Now I want to combine the all the above files using a for-loop into a single file like this:

Multiple na.strings in read.table() function in R

一曲冷凌霜 提交于 2019-11-30 17:34:01
问题 I have a square table and it has two na.strings (e.g. "A" and "B") that I need to turn into NA. So far I can turn either one of those into NA but not both. How should I do this? Can I use a function in that argument? If yes, what function should I use? I tried like ( na.strings = "A" | "B" ) and ( na.strings = "A | B" ) but it does not work. My code is as follows: loadfile<-read.table("test.csv", header=T, sep=",", na.strings="A | B") 回答1: na.strings takes a character vector, so... loadfile <

preserve old (pre 3.1.0) type.convert behavior

你说的曾经没有我的故事 提交于 2019-11-30 17:28:32
R 3.1.0 is out and one of the new features is the following: type.convert() (and hence by default read.table() ) returns a character vector or factor when representing a numeric input as a double would lose accuracy. Similarly for complex inputs. To give an example: df <- read.table(text = "num1 num2 1.1 1.1234567890123456 2.2 2.2 3.3 3.3", header = TRUE) sapply(df, class) # num1 num2 # "numeric" "factor" while with previous versions, read.table would have returned two numeric columns. For those who like me are a concerned about that change, what can be done to preserve the old behavior? Note: