read.csv

how to read multiple (loop) .csv files with a date name in R?

元气小坏坏 提交于 2019-12-12 04:47:27
问题 I have several .csv files with these names (from 1 January 2016 to 31 december 2016) 01012016.csv 02012016.csv ... 31122016.csv I want to use read.csv( by using a loop but still considering date patterns. start<-as.Date("01-01-16") end<-as.Date("31-12-16") theDate<-start ­{read.csv(theDate,".csv")} 回答1: You can get the names of all the files using list.files and giving it the path of all folder where all the files are located: filenames = list.files('/path/to/datefiles/', pattern = "*.csv")

Clean up code and keep null values from crashing read.csv.sql

我与影子孤独终老i 提交于 2019-12-11 23:21:52
问题 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) library

R wanting to limit the amount of digits from csv file

点点圈 提交于 2019-12-11 19:03:39
问题 There are plenty of threads about people thinking they have lost digits when reading in a csv file, and it's just a digits setting that isn't displaying all of them. I on the other hand want to round or truncate my incoming data to two decimal places. I am having an issue in Rmarkdown where I can't limit the decimal places after highlighting fields. This has lead to me attempting to round before the highlighting, but that leads to undesirable results if I go lower than 4 places since I am

How to load a CSV txt file into R correctly

时光怂恿深爱的人放手 提交于 2019-12-11 14:12:45
问题 I'm very new to R, and having some simple trouble. I thought I understood the read.table() function, but apparently not. I'm trying to load "http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt" into RStudio, and for whatever reason, it only displays the text file again. My command was: read.table("http://www.stat.berkeley.edu/users/nolan/data/bikeshare.txt", sep=",", header=True) Any help is much appreciated. Thanks. 回答1: Here is an example: Code Example: URL <- "http://www.stat

read.csv() warning: unable to read a csv file in R

孤街浪徒 提交于 2019-12-11 11:59:53
问题 I was trying to read a csv file in R and read.csv gives me a warning and consequently stops reading from there on. I think it's something related to an extra quote being there. How can I resolve this? (csv file put on a public share below for access) > scoresdf = read.csv('http://aftabubuntu.cloudapp.net/trainDataEnglish.csv') Warning message: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : EOF within quoted string 回答1: I got the same error on read.csv . I managed to

Find all the combinations of a particular column and find their frequencies

帅比萌擦擦* 提交于 2019-12-11 07:58:58
问题 My file is like this- Pcol Mcol P1 M1,M2,M5,M6,M1,M2,M1.M5 P2 M1,M2,M3,M5,M1,M2,M1,M3 P3 M4,M5,M7,M6,M5,M7,M4,M7 I want to find all the combination of Mcol elements and find these combinatinatons are present in how many rows . Expected output- Mcol freq M1,M2 2 M1,M5 2 M1,M6 1 M2,M5 2 M2,M6 1 M5,M6 2 M1,M3 1 M2,M3 1 M4,M5 1 M4,M7 1 M4,M6 1 M7,M6 1 I have tried this- x <- read.csv("file.csv" ,header = TRUE, stringsAsFactors = FALSE) xx <- do.call(rbind.data.frame, lapply(x$Mcol, function(i){ n

R correct use of read.csv

守給你的承諾、 提交于 2019-12-11 05:39:43
问题 I must be misunderstanding how read.csv works in R. I have read the help file, but still do not understand how a csv file containing: 40900,-,-,-,241.75,0 40905,244,245.79,241.25,244,22114 40906,244,246.79,243.6,245.5,18024 40907,246,248.5,246,247,60859 read into R using: euk<-data.matrix(read.csv("path\to\csv.csv")) produces this as a result (using tail ): Date Open High Low Close Volume [2713,] 15329 490 404 369 240.75 62763 [2714,] 15330 495 409 378 242.50 127534 [2715,] 15331 1 1 1 241.75

R 3.5 - read.csv not able to read UTF-16 csv file

依然范特西╮ 提交于 2019-12-10 14:12:38
问题 My code is as follows: read.csv("http://asic.gov.au/Reports/YTD/2018/RR20180420-001-SSDailyYTD.csv", skip=1, fileEncoding = "UTF-16", sep = "\t", header = FALSE) R 3.4.3 - Code executes cleanly R 3.5.0 - gives the following error: Error in read.table(file = file, header = header, sep = sep, quote = quote, : no lines available in input @hrbrmstr - session info readout sessionInfo() R version 3.5.0 (2018-04-23) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build

Skip all leading empty lines in read.csv

筅森魡賤 提交于 2019-12-10 13:59:44
问题 I am wishing to import csv files into R, with the first non empty line supplying the name of data frame columns. I know that you can supply the skip = 0 argument to specify which line to read first. However, the row number of the first non empty line can change between files. How do I work out how many lines are empty, and dynamically skip them for each file? As pointed out in the comments, I need to clarify what "blank" means. My csv files look like: ,,, w,x,y,z a,b,5,c a,b,5,c a,b,5,c a,b,4

fread: read certain row as implicitly ordered factor

一笑奈何 提交于 2019-12-10 11:54:35
问题 I am fairly new to R , and have been using data.table a lot recently for a project involving manipulation of large data sets, specifically genome data. One of the columns is the chromosome number/name, which is formatted as "chr_", where the _ is 1-22, X, or Y. As the data is sorted by chromosomal position, this is a natural primary key for my data. However, setting this as the key produces unwanted results, namely sorting by lexicographic order rather than general numeric order (i.e. the