read.table

How to avoid space while reading .txt file

久未见 提交于 2019-12-12 03:29:00
问题 I am trying to read a file which has a column of + and - but apparently associated with a space after that. In anyway I read ( read.csv or read.table or read_excel that file I pick up the space after. For example: df = data.frame(x = c('a', 'b', 'c'), y = c('+ ', "- ", "+ ")) df x y 1 a + 2 b - 3 c + Now, is there a way to specifically instruct not to pick up space after the value in read.csv or read_excel Or is there a way to clean up the spaces after reading into a dataframe? 来源: https:/

R: read fasta files into data.frame using base R - NOT Biostrings (and the like)

瘦欲@ 提交于 2019-12-12 01:55:52
问题 How can one read FASTA files directly into a data frame in R using base code. These files store information bio-sequence (e.g. DNA or protein) and have 2*n lines for n individual bio-molecules (id1 through idn), and thus are of the type: >id1 #(always starts with a `>`) seq1 >id2 seq2 ... >idn seqn If one want to be in base R (instead of dedicated packages like Biostrings and seqinr , which make use of novel classes for various manipulations of bio-sequences), how can you use e.g. read.table

How to read a non-rectangular matrix into R

无人久伴 提交于 2019-12-12 01:39:57
问题 I have a large matrix of gene ID's followed by a series of bootstrap values. For example: NM_001040105 1.80711736583 0.877742720548 1.0842704195 1.80711736583 0.505992862434 0.877742720548 1.37340919803 0.722846946334 1.0842704195 1.0842704195 2.52996431217 1.80711736583 1.0842704195 2.52996431217 1.80711736583 1.0842704195 1.37340919803 1.37340919803 1.0842704195 1.37340919803 0.877742720548 1.0842704195 2.52996431217 1.80711736583 1.80711736583 0.877742720548 0.877742720548 0.877742720548 1

foreach loop returns only result of first data in the list

 ̄綄美尐妖づ 提交于 2019-12-11 09:09:10
问题 I have been struggling about making read of my data from a directory and make a function into a foreach loop, filelist <- dir(pattern = "*.omf") readfiles <- function(m){for(k in 1:length(filelist)) file<-filelist[[k]] data <- read.table("filelist[[k]]", skip=grep('# Begin: Data Text', readLines("filelist[[k]]")),na.strings=c("NA", "-", "?"),colClasses="numeric") my <- as.matrix(data[1:57600,2]); mesh <- array(my, dim = c(120,60,8)); Ms<-1350*10^3 # A/m asd2=(mesh[70:75,24:36 ,2])/Ms; # in A

How to handle data with no space between separators when using fread in R

折月煮酒 提交于 2019-12-11 07:27:20
问题 I am reading a large .txt file (>1GB) into R via fread . I am reading the file in directly from a .zip archive, via a bash command: base = fread('unzip -p Folder.zip File.txt', sep = '|', header = FALSE, stringsAsFactors = FALSE, na.strings="", quote = "", col.names = col_namesMain) The text file separates entries via | so that a typical line might look like: RRX|||02020||333293||||12123 However, there are many places where empty entries are denoted by separators with no space between them, e

Read only n-th column of a text file which has no header with R and sqldf

佐手、 提交于 2019-12-11 06:22:26
问题 I have a similiar problem like this question: selecting every Nth column in using SQLDF or read.csv.sql I want to read some columns of large files (table of 150rows, >500,000 columns, space separated, filled with numeric data and only a 32 bit system available). This file has no header, therefore the code in the thread above didn't work and I decided to write a new post. Do you have an idea to solve this problem? I thought about something like that, but any results with fread or read.table

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

Why write.csv and read.csv are not consistent? [closed]

陌路散爱 提交于 2019-12-10 02:25:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . The problem is simple, consider the following example: m <- head(iris) write.csv(m, file = 'm.csv') m1 <- read.csv('m.csv') The result

read.csv vs. read.table

懵懂的女人 提交于 2019-12-09 05:08:44
问题 I have seen in several cases that while read.table() is not able to read a tab delimited file (for example the annotation table of a microarray) returning the following error: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line xxx did not have yyy elements read.csv() works perfectly on the same file with no errors. I think also the speed of read.csv() is also higher than read.table() . Even more: read.table() is doing very crazy reading a file of me. It makes

In read.table(): incomplete final line found by readTableHeader

泄露秘密 提交于 2019-12-09 04:42:42
问题 I have a CSV when I try to read.csv() that file, I get the warning warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on ... And I cannot isolate the problem, despite scouring StackOverflow and R-help for solutions. This is the Dropbox link for the data: https://www.dropbox.com/s/h0fp0hmnjaca9ff/PING%20CONCOURS%20DONNES.csv 回答1: As explained by Hendrik Pon,The message indicates that the last line of the file