read.table

read file with single line into R in fread or read.table

允我心安 提交于 2021-02-08 04:59:24
问题 I want to read a txt file into R this file has only file line, like this 1 NYC 2013-12-30 82 PM2.5 Ⅱ fair 2 London 2013-12-30 66 PM10.0 Ⅱ good there're no \n in this file, and all the what I want is a data.table incorporating these information like this: 1 NYC 2013-12-30 82 PM2.5 Ⅱ fair 2 London 2013-12-30 66 PM10.0 Ⅱ good Luckily, there're no NAs in the file, also I know for sure there're 7 fields for each observations. Could I achieve this using fread? or read.table? I tried this test <-

Read table with comment lines starting with “##”

两盒软妹~` 提交于 2020-06-27 07:51:09
问题 I'm struggling to read my tables in Variant Call Format (VCF) with R. Each file has some comment lines starting with ## , and then the header starting with # . ## contig=<ID=OTU1431,length=253> ## contig=<ID=OTU915,length=253> #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT /home/sega/data/bwa/reads/0015.2142.fastq.q10sorted.bam Eubacterium_ruminantium_AB008552 56 . C T 228 . DP=212;AD=0,212;VDB=0;SGB=-0.693147;MQ0F=0;AC=2;AN=2;DP4=0,0,0,212;MQ=59 GT:PL 1/1:255,255,0 How can I read such table

What is the fastest way and fastest format for loading large data sets into R [duplicate]

风流意气都作罢 提交于 2020-06-25 07:02:34
问题 This question already has answers here : Quickly reading very large tables as dataframes (11 answers) Closed 4 years ago . I have a large dataset (about 13GB uncompressed) and I need to load it repeatedly. The first load (and save to a different format) can be very slow but every load after this should be as fast as possible. What is the fastest way and fastest format from which to load a data set? My suspicion is that the optimal choice is something like saveRDS(obj, file = 'bigdata.Rda',

R read.csv how to ignore carriage return?

╄→гoц情女王★ 提交于 2020-02-21 15:02:39
问题 I need to read a text file (tab-separated) that has some carriage returns inside some fields. If I use read.table, it gives me an error: line 6257 did not have 20 elements If I use read.csv, it doesn't give an error, but creates a new line in that place, putting the next fields in the first fields of the new line. How can I avoid this? I can't alter the file itself (the script is to be run elsewhere). Also the broken strings don't have quotation marks (no strings in the file have). One option

R read.csv how to ignore carriage return?

微笑、不失礼 提交于 2020-02-21 15:00:58
问题 I need to read a text file (tab-separated) that has some carriage returns inside some fields. If I use read.table, it gives me an error: line 6257 did not have 20 elements If I use read.csv, it doesn't give an error, but creates a new line in that place, putting the next fields in the first fields of the new line. How can I avoid this? I can't alter the file itself (the script is to be run elsewhere). Also the broken strings don't have quotation marks (no strings in the file have). One option

R read.csv how to ignore carriage return?

断了今生、忘了曾经 提交于 2020-02-21 14:51:53
问题 I need to read a text file (tab-separated) that has some carriage returns inside some fields. If I use read.table, it gives me an error: line 6257 did not have 20 elements If I use read.csv, it doesn't give an error, but creates a new line in that place, putting the next fields in the first fields of the new line. How can I avoid this? I can't alter the file itself (the script is to be run elsewhere). Also the broken strings don't have quotation marks (no strings in the file have). One option

Reading seperate text files and saving them in a single variable as seperate dataframes

╄→尐↘猪︶ㄣ 提交于 2020-01-24 21:47:29
问题 I have multiple text files (tab-delimited) generated from the same software. I initially used a loop with assign function to create variables dynamically and store them separately with the read.table function. This resulted in too many variables and was obviously time-consuming to apply operations on separate files. I came across the lapply and fread method shown in the code below. I don't need to merge them and they need to be separate data frames so I can compare values in the files. Using

read.delim() - errors “more columns than column names” and “header and ''col.names” are of different lengths"

荒凉一梦 提交于 2020-01-23 06:45:07
问题 Preliminary information OS: Windows XP Professional Version 2002 Service Pack 3; R version: R 2.12.2 (2011-02-25) I am attempting to read a 30,000 row by 80 column, tab-delimited text file into R using the read.delim() function. This file does have column headers with following naming convention: "_". The code that I use to attempt to read the data in is: cc <- c("integer", "character", "integer", rep("character", 3), rep("integer", 73)) example_data <- read.delim(file = 'C:/example.txt', row

read.table reads “T” as TRUE and “F” as FALSE, how to avoid?

不打扰是莪最后的温柔 提交于 2020-01-21 04:04:28
问题 I have a file with the data c("A","T","B","F") . When I use: read.csv(myfile,header=F,stringsAsFactors=F) R interprets character T as TRUE and F as FALSE Am I doing anything wrong? 回答1: If all your columns are characters then try this: # replace text = . with your filename read.csv(text="A,B,T,T", header=FALSE, stringsAsFactors=FALSE, colClasses = c("character")) Else, you'll have to pass the type of each column in colClasses as: colClasses = c("numeric", "numeric", "character", ...) 回答2: I

Speed up import of fixed width format table in R

浪尽此生 提交于 2020-01-15 04:45:07
问题 I'm importing table from a fixed width format .txt file in R. This table has about 100 observations and 200000 lines (a few lines below). 11111 2008 7 31 21 2008 8 1 21 3 4 6 18 4 7 0 12 0 0 0 0 0 1 0 0 0 0 0 0 0 5 0 0 7 5 0 1 0 2 0 0 0 0 0 0 2 0 0 0.0 5 14.9 0 14.9 0 14.0 0 16.5 0 14.9 0 15.6 0 15.3 0 0 15.6 0 15.6 0 17.6 0 16.1 0 17.10 0 1 97 0 0.60 0 1 15.1 0 986.6 0 1002.9 0 7 0 0.2 0 11111 2008 8 1 0 2008 8 1 0 4 7 6 18 4 98 0 1 9 0 0 0 2 0 1 0 0 0 0 0 0 0 5 0 0 7 0 0 0 1 0 2 0 260 0 1 0