read.table

How can you read a CSV file in R with different number of columns

房东的猫 提交于 2019-11-26 05:26:05
问题 I have a sparse data set, one whose number of columns vary in length, in a csv format. Here is a sample of the file text. 12223, University 12227, bridge, Sky 12828, Sunset 13801, Ground 14853, Tranceamerica 14854, San Francisco 15595, shibuya, Shrine 16126, fog, San Francisco 16520, California, ocean, summer, golden gate, beach, San Francisco When I use read.csv(\"data.txt\", header = F) R will interpret the data set as having 3 columns because the size is determined from the first 5 rows.

How do you read in multiple .txt files into R? [duplicate]

纵饮孤独 提交于 2019-11-26 01:39:51
问题 This question already has an answer here: How to import multiple .csv files at once? 10 answers I\'m using R to visualize some data all of which is in .txt format. There are a few hundred files in a directory and I want to load it all into one table, in one shot. Any help? EDIT: Listing the files is not a problem. But I am having trouble going from list to content. I\'ve tried some of the code from here, but I get a bug with this part: all.the.data <- lapply( all.the.files, txt , header=TRUE)

Specify custom Date format for colClasses argument in read.table/read.csv

删除回忆录丶 提交于 2019-11-26 00:31:52
问题 Question: Is there a way to specify the Date format when using the colClasses argument in read.table/read.csv? (I realise I can convert after importing, but with many date columns like this, it would be easier to do it in the import step) Example: I have a .csv with date columns in the format %d/%m/%Y . dataImport <- read.csv(\"data.csv\", colClasses = c(\"factor\",\"factor\",\"Date\")) This gets the conversion wrong. For example, 15/07/2008 becomes 0015-07-20 . Reproducible code: data <-