read.csv

read.csv vs. read.table

懵懂的女人 提交于 2019-12-09 05:08:44
问题 I have seen in several cases that while read.table() is not able to read a tab delimited file (for example the annotation table of a microarray) returning the following error: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line xxx did not have yyy elements read.csv() works perfectly on the same file with no errors. I think also the speed of read.csv() is also higher than read.table() . Even more: read.table() is doing very crazy reading a file of me. It makes

sapply vs. lapply while reading files and rbind'ing them

痞子三分冷 提交于 2019-12-08 19:44:27
I followed Hadley's thread: Issue in Loading multiple .csv files into single dataframe in R using rbind to read multiple CSV files and then convert them to one dataframe. I also experimented with lapply vs. sapply as discussed on Grouping functions (tapply, by, aggregate) and the *apply family . Here's my first CSV file: dput(File1) structure(list(First.Name = structure(c(1L, 2L, 1L, 1L, 1L), .Label = c("A", "C"), class = "factor"), Last.Name = structure(c(1L, 2L, 2L, 2L, 2L), .Label = c("B", "D"), class = "factor"), Income = c(55L, 23L, 34L, 45L, 44L), Tax = c(23L, 21L, 22L, 24L, 25L),

sapply vs. lapply while reading files and rbind'ing them

天大地大妈咪最大 提交于 2019-12-08 06:09:19
问题 I followed Hadley's thread: Issue in Loading multiple .csv files into single dataframe in R using rbind to read multiple CSV files and then convert them to one dataframe. I also experimented with lapply vs. sapply as discussed on Grouping functions (tapply, by, aggregate) and the *apply family. Here's my first CSV file: dput(File1) structure(list(First.Name = structure(c(1L, 2L, 1L, 1L, 1L), .Label = c("A", "C"), class = "factor"), Last.Name = structure(c(1L, 2L, 2L, 2L, 2L), .Label = c("B",

read.csv() and colClasses [duplicate]

淺唱寂寞╮ 提交于 2019-12-08 00:25:41
问题 This question already has answers here : Error in <my code> : object of type 'closure' is not subsettable (5 answers) Closed 5 years ago . I am trying to use read.csv() command, but I do not understand colClasses part to run coding. Does anyone explain what it is, and also give me example of simple coding for read.csv() ? Also, if I run my coding for read.csv() , I get an error > object of type 'closure' is not subsettable What type of error is this? Last time I run my code, it worked, but

Error in file(file, “rt”) : cannot open the connection - cannot open file 'specdata' access denied

核能气质少年 提交于 2019-12-07 09:03:08
问题 I'm running rStudio v3.1.2 on Windows 7. This laptop is a 64-bit machine. I'm taking the JHU R Programming course offered by Coursera and am stuck on an error I'm receiving in part 1 of the problem. I have some error handling functions I'm keeping out of this example so I'm really just trying to show what I absolutely need to. The only reason I include the messages is the demonstrate that all the conditions must be satisfied in order to proceed. pollutantmean <- function(directory, pollutant,

fread - read all columns as character

主宰稳场 提交于 2019-12-07 06:17:09
问题 I'm trying to read a file into R using data.table / fread . Some of the fields have leading zeros and I just want to read the data in as characters and manually fix them. However I can't figure out how to convey this to fread . I'm trying this and it's assigning char, num, etc types as it normally would : prop1 <- data.frame(fread("C:\\myFile.csv"), stringsAsFactors = F, colClasses = c(rep('character',58))) What am I missing? 回答1: Your colClasses argument is in the wrong place. It needs to be

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,

read.csv() - two out of three columns [duplicate]

你离开我真会死。 提交于 2019-12-06 04:34:42
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Only read limited number of columns in R I have a ascii-dataset which consists of three columns, but only the last two are actual data. Now I want to dotchart the data by using read.csv(file = "result1", sep= " ") . R reads all three columns. How do I avoid this? 回答1: You can use the colClasses argument to skip columns: mydata <- read.csv('mydata.csv', colClasses=c('NULL',NA,NA)) or mydata <- read.csv('mydata

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

Insert NA values into dataframe blank cells when importing read.csv/read.xlsx

允我心安 提交于 2019-12-03 08:21:23
The attached screenshot shows part of a dataframe which I have just imported into R from an excel file. In the cells which are blank, I need to insert 'NA'. How can I insert NA into any cell which is blank (whilst leaving the already populated cells alone)? The better question is how can I read it into R so the missing cells will already be NA s. Maybe you used something like this: read.csv(file, header=FALSE, strip.white = TRUE, sep=",") Specify the NA strings like this when you read it in: read.csv(file, header=FALSE, strip.white = TRUE, sep=",", na.strings= c("999", "NA", " ", "")) to