read.csv

R's read.csv() omitting rows

旧街凉风 提交于 2019-12-23 15:14:22
问题 In R, I'm trying to read in a basic CSV file of about 42,900 rows (confirmed by Unix's wc -l). The relevant code is vecs <- read.csv("feature_vectors.txt", header=FALSE, nrows=50000) where nrows is a slight overestimate because why not. However, >> dim(vecs) [1] 16853 5 indicating that the resultant data frame has on the order of 17,000 rows. Is this a memory issue? Each row consists of a ~30 character hash code, a ~30 character string, and 3 integers, so the total size of the file is only

Prevent variable name getting mangled by read.csv/read.table?

喜你入骨 提交于 2019-12-20 04:58:14
问题 My data set testdata has 2 variables named PWGTP and AGEP The data are in a .csv file. When I do: > head(testdata) The variables show up as ï..PWGTP AGEP 23 55 26 56 24 45 22 51 25 54 23 35 So, for some reason, R is reading PWGTP as ï..PWGTP . No biggie. HOWEVER, when I use some function to refer to the variable ï..PWGTP , I get the message: Error: id variables not found in data: ï..PWGTP Similarly, when I use some function to refer to the variable PWGTP , I get the message: Error: id

Notation issues with read.csv.sql in r

为君一笑 提交于 2019-12-20 04:37:42
问题 I am using read.csv.sql to conditionally read in data ( my data set is extremely large so this was the solution I chose to filter it and reduce it in size prior to reading the data in ). I was running into memory issues by reading in the full data and then filtering it so that is why it is important that I use the conditional read so that the subset is read in, versus the full data set. Here is a small data set so my problem can be reproduced: write.csv(iris, "iris.csv", row.names = F) I am

read.csv(“http://ichart.finance.yahoo.com/table.csv?s=SPY”) Not Working

試著忘記壹切 提交于 2019-12-19 10:16:36
问题 I have been using the following command for a long time without problem: spy <- read.csv("http://ichart.finance.yahoo.com/table.csv?s=SPY") But in the past few days it started to throw the following error: Warning messages: 1: In file(file, "rt") : "internal" method cannot handle https redirection to: 'https://ichart.finance.yahoo.com/table.csv?s=SPY' 2: In file(file, "rt") : "internal" method failed, so trying "libcurl" I've updated my RStudio, R and all packages to the most up-to-date

How to read quoted text containing escaped quotes

喜你入骨 提交于 2019-12-18 11:30:35
问题 Consider the following comma separated file. For simplicity let it contain one line: 'I am quoted','so, can use comma inside - it is not separator here','but can\'t use escaped quote :=(' If you try to read it with the command table <- read.csv(filename, header=FALSE) the line will be separated to 4 parts, because line contains 3 commas. In fact I want to read only 3 parts, one of which contains comma itself. There quote flag comes for help. I tried: table <- read.csv(filename, header=FALSE,

Merging df.1, df.2, df.3 … df.x into one dataframe

ⅰ亾dé卋堺 提交于 2019-12-17 16:54:24
问题 I am working on a project that imports all csv files from a given folder and merges them into one file. I was able to import the rows and columns I wanted from each of the files from the folder but now need help merging them all into one file. I do not know how many files I will eventually end up with (probably around 120) so I do not want to merge them 1 by 1. Here is what I have so far: # Import All files rowsToUse <- c(9:104,657:752) colsToUse <- c(15,27,28,29,30,33,35) filenames <- list

Read csv with dates and numbers

旧城冷巷雨未停 提交于 2019-12-17 15:57:12
问题 I have a problem when I import a csv file with R: example lines to import: 2010-07-27;91 2010-07-26;93 2010-07-23;88 I use the statement: data <- read.csv2(file="...", sep=";", dec=".", header=FALSE) when I try to aggregate this data with other ones originated by statistical analysis using cbind , the date is showed as an integer number because it was imported as factor. If I try to show it as a string using as.character , the numerical data are transformed into characters too so they are

How can I read the header but also skip lines - read.table()?

穿精又带淫゛_ 提交于 2019-12-17 09:33:28
问题 Data.txt: Index;Time; 1;2345; 2;1423; 3;5123; The code: dat <- read.table('data.txt', skip = 1, nrows = 2, header =TRUE, sep =';') The result: X1 X2345 1 2 1423 2 3 5123 I expect the header to be Index and Time, as follows: Index Time 1 2 1423 2 3 5123 How do I do that? 回答1: I am afraid, that there is no direct way to achieve this. Either you read the entire table and remove afterwards the lines you don't want or you read in the table twice and assign the header later: header <- read.table(

Error while reading csv file

耗尽温柔 提交于 2019-12-13 09:27:19
问题 I have a xlsx file and to read from Rstudio i saved it as .csv file. Now when i try to read the file from Rstudio, receiving the below error. setwd("D:/DATA SCIENCE/CCPP-Linear regression") ccpp<- read.csv("Folds5x2_pp.csv", header = TRUE) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Folds5x2_pp.csv': No such file or directory 回答1: As already mentioned in the comments, the "cannot open the connection" part of the

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

故事扮演 提交于 2019-12-13 02:36:04
问题 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 cxfm 1C 0 2 d2 H50 2 3 g3g 1G 2 4 hb E37 1 5 nlx E45 4 instead of getting this one: name type qty 1 cxfm 1C 0 2 d2 H50 2 3 g3g 1G 2 4 hb E37 1 5 nlx E45 4 Any ideas this? this is what I am using to read the files: file_list<-list.files() for (file in file_list){ if (!exists("dataset")){ dataset