read.table

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(

read.csv warning 'EOF within quoted string' prevents complete reading of file

点点圈 提交于 2019-12-17 03:50:59
问题 I have a CSV file (24.1 MB) that I cannot fully read into my R session. When I open the file in a spreadsheet program I can see 112,544 rows. When I read it into R with read.csv I only get 56,952 rows and this warning: cit <- read.csv("citations.CSV", row.names = NULL, comment.char = "", header = TRUE, stringsAsFactors = FALSE, colClasses= "character", encoding= "utf-8") Warning message: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : EOF within quoted string I can read

Speed up reading data in console using read.table(text=“…”) RStudio

两盒软妹~` 提交于 2019-12-13 18:41:56
问题 I find myself pulling bits of data here and there from old excel files I have stored from past projects. These files are unorganized, I mean no common format of rows and columns so it would be useless to read the entire spreadsheet directly into R, and most of the time I just want to grab a couple columns and rows of data at a time anyway. Rather than creating a separate text file with the columns/rows I want and reading this file in I find the easiest way to get the data is to use read.table

Importing fread vs read.table and errors

为君一笑 提交于 2019-12-13 08:27:08
问题 When I import a .csv file with read.table, with the call df <- read.table("ModelSugar(new) real_thesis_experiment-table_1.csv", skip = 6, sep = ",", head = TRUE) and I check the summary of the data I get (only first 3 columns of 45 are shown): X.run.number. scenario configuration Min. : 1 "pessimistic":999994 "central":999994 1st Qu.: 650 Median :1299 Mean :1299 3rd Qu.:1949 Max. :2600 With this dataframe I can make nice graphics. However, I have 80 .csv files with a total size of 40 GB, so I

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

read.table line 15 does not contain 23 elements - R

限于喜欢 提交于 2019-12-13 00:32:03
问题 here is the code I used: d = read.table("Movies.txt", sep="\t", col.names=c( "id", "name", "date", "link", "c1", "c2", "c3","c4", "c5", "c6","c7", "c8", "c9","c10", "c11", "c12","c13", "c14", "c15","c16", "c17", "c18", "c19"), fill=FALSE, strip.white=TRUE) and here is the text file: 1 Toy Story (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?Toy%20Story%20(1995) 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 GoldenEye (1995) 01-Jan-95 http://us.imdb.com/M/title-exact?GoldenEye%20(1995) 0 1 1 0 0 0

reading a table in R?

风格不统一 提交于 2019-12-12 21:09:20
问题 I have a txt file with the following structure: NAME DATA1 DATA2 a 10 1,2,3 b 6 8,9 c 20 5,6,7 ,8 The first line represent the header and the data is separated by tabs . I need to put the elements of DATA1 in a list or vector in a way that I can traverse the elements one by one. Also I need to extract the elements of DATA2 for each NAME and to put them in a list so I can traverse then individually, e.g. get the elements 8,9 for NAME b and put it into a list. (Note that the third record has a

fread data.table in R doesn't read in column names

浪尽此生 提交于 2019-12-12 15:22:42
问题 When reading in a data file into R, I can read it in either as a data.frame or a data.table using the data.table package. I would prefer to use data.table in the future since it deals with large data better. However, there are issues with both methods ( read.table for data.frames, fread for data.tables) and I'm wondering if there's a simple fix out there. When I use read.table to produce a data.frame , if my column names include colons or spaces, they are replaced by periods, which I do not

Is it possible to read two tables from the same text file?

橙三吉。 提交于 2019-12-12 05:24:38
问题 For instance, if I have a text file (mytext.txt) with the following text: Table1 13 3 20 0 0 0 0 3 10 0 0 0 6 0 20 0 5 0 0 0 0 0 0 0 7 20 0 0 0 0 0 20 19 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 13 Table2 0 2 10 -5 3 -10 -5 Can I retrieve both of them and get two tables? So that if I print my data table1 I would get the first table and if I print my data table 2 I would get the second table. I know that if mytext.txt only had one table I could do something like: table1 <- read.table("mytext.txt") 回答1: 1

R read.csv from URL error in knitr

最后都变了- 提交于 2019-12-12 04:55:33
问题 When I run this code in the R console, it works fine: read.csv('https://courses.edx.org/c4x/MITx/15.071x_2/asset/WHO.csv') But when I try to put in into an R markdown document and knit it, I get the following: Error in open.connection(file, "rt") : cannot open the connection Calls: <Anonymous> ... eval -> read.csv -> read.table -> open -> open.connection Execution halted I also tried using http and url() , but neither helped read.csv('http://courses.edx.org/c4x/MITx/15.071x_2/asset/WHO.csv')