read.table

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

淺唱寂寞╮ 提交于 2019-12-09 02:22:04
问题 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,

fill=TRUE will fail when different number of column occurr after 5 rows in read.table? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-07 13:13:24
问题 This question already has answers here : How can you read a CSV file in R with different number of columns (3 answers) Closed 4 years ago . Let's say we have a file name test.txt which contains unknown number of columns: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6 7 8 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 fill=T fails when line 8 has more than 5 columns: read.table('test.txt', header=F, sep='\t', fill=T) results: V1 V2 V3 V4 V5 1 1 2 3 4 5 2 1 2 3

Skip empty files when importing text files

醉酒当歌 提交于 2019-12-07 01:52:31
问题 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, sep=",") data$species <- strsplit(f, split = "c.txt") <-- (column name is filename) DF <- rbind(DF, data) } write.xlsx(DF,"B:/trends.xlsx") Problem is, there are about 100 files that are empty. so the code stops at the first empty file and I get this

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

我的未来我决定 提交于 2019-12-07 01:46:47
问题 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 1.00 0.00 0.00 0.00 0 3 0.12 0.03 1.00 0.00 0.00 0 4 -0.04 0.54 0.32 1.00 0.00 0 5 -0.12 0.57 -0.09 0.26 1.00 0 6 0.21 -0.04 0.24 0.18 -0.21 1 It goes well. But then: corrplot(data, method = 'color', addCoef.col="grey") It is said that: Error in matrix(unlist(value,

Import raw data into R

不问归期 提交于 2019-12-05 06:14:56
问题 please anyone can help me to import this data into R from a text or dat file. It has space delimited, but cities names should not considered as two names. Like NEW YORK. 1 NEW YORK 7,262,700 2 LOS ANGELES 3,259,340 3 CHICAGO 3,009,530 4 HOUSTON 1,728,910 5 PHILADELPHIA 1,642,900 6 DETROIT 1,086,220 7 SAN DIEGO 1,015,190 8 DALLAS 1,003,520 9 SAN ANTONIO 914,350 10 PHOENIX 894,070 回答1: For your particular data frame, where true spaces only occur between capital letters, consider using a regular

Skip empty files when importing text files

≡放荡痞女 提交于 2019-12-05 06:09:27
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, sep=",") data$species <- strsplit(f, split = "c.txt") <-- (column name is filename) DF <- rbind(DF, data) } write.xlsx(DF,"B:/trends.xlsx") Problem is, there are about 100 files that are empty. so the code stops at the first empty file and I get this error message: Error in read.table(f, header = F, sep = ",") : no lines available in input Is there a

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

妖精的绣舞 提交于 2019-12-05 04:51:14
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 1.00 0.00 0.00 0.00 0 3 0.12 0.03 1.00 0.00 0.00 0 4 -0.04 0.54 0.32 1.00 0.00 0 5 -0.12 0.57 -0.09 0.26 1.00 0 6 0.21 -0.04 0.24 0.18 -0.21 1 It goes well. But then: corrplot(data, method = 'color', addCoef.col="grey") It is said that: Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : length of 'dimnames' [2] not equal to array extent I don

Why write.csv and read.csv are not consistent? [closed]

人走茶凉 提交于 2019-12-05 01:15:26
The problem is simple, consider the following example: m <- head(iris) write.csv(m, file = 'm.csv') m1 <- read.csv('m.csv') The result of this is that m1 is different from the original object m in that it has a new first column named "X". If I really wanted to make them equal, I have to use additional arguments, like in these two examples: write.csv(m, file = 'm.csv', row.names = FALSE) # and then m1 <- read.csv('m.csv') or write.csv(m, file = 'm.csv') m1 <- read.csv('m.csv', row.names = 1) The question is, what is the reason of this difference? in particular, why if write.csv and read.csv are

read.table with comma separated values and also commas inside each element

夙愿已清 提交于 2019-12-04 05:25:50
I'm trying to create a table from a csv file comma separated. I'm aware that not all the rows have the same number of elements so I would write some code to eliminate those rows. The problem is that there are rows that include numbers (in thousands) which include another comma as well. I'm not capable of splitting those rows properly, here's my code: pURL <- "http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=EI&region=FRA&order=asc" res <- read.table(pURL, header=T, sep='\t', dec = '.', stringsAsFactors=F) x <- unlist( lapply(keyRatios, function(u) strsplit(u,split='\n'))

Reading in multiple CSVs with different numbers of lines to skip at start of file

怎甘沉沦 提交于 2019-12-03 05:58:59
I have to read in about 300 individual CSVs. I have managed to automate the process using a loop and structured CSV names. However each CSV has 14-17 lines of rubbish at the start and it varies randomly so hard coding a 'skip' parameter in the read.table command won't work. The column names and number of columns is the same for each CSV. Here is an example of what I am up against: QUICK STATISTICS: Directory: Data,,,, File: Final_Comp_Zn_1 Selection: SEL{Ox*1000+Doma=1201} Weight: None,,, ,,Variable: AG,,, Total Number of Samples: 450212 Number of Selected Samples: 277 Statistics VARIABLE,Min