Re: [R] help with read.csv() for files with different number of columns

2017-08-29 Thread David Winsemius
> On Aug 29, 2017, at 2:59 PM, Jim Lemon wrote: > > Hi Ace, > You can just read the file first to find out: > > max_fields<-function(file,sep=" ") { > rlines<-readLines(file) > return(max(unlist(lapply(sapply(rlines,strsplit,sep),length > } > nmax<-max_fields(test.txt,"\t") > > Jim Or jus

Re: [R] help with read.csv() for files with different number of columns

2017-08-29 Thread Jim Lemon
Hi Ace, You can just read the file first to find out: max_fields<-function(file,sep=" ") { rlines<-readLines(file) return(max(unlist(lapply(sapply(rlines,strsplit,sep),length } nmax<-max_fields(test.txt,"\t") Jim On Wed, Aug 30, 2017 at 2:22 AM, Fix Ace wrote: > Thank you very much! Lo

Re: [R] help with read.csv() for files with different number of columns

2017-08-29 Thread Fix Ace via R-help
Thank you very much! Looks like I have to know the length of each record ahead of time. Ace On Monday, August 28, 2017 12:56 AM, Jim Lemon wrote: Hi Ace, With tabs as separators: testdf<-read.table("test.txt",header=FALSE,fill=TRUE,sep="\t", col.names=paste("V",1:19,sep=""),stringsAsF

Re: [R] help with read.csv() for files with different number of columns

2017-08-27 Thread Fix Ace via R-help
Hi, Jim, Thank you very much for pointing out the format issue. Here is the original text: ===I have a text file (test.txt) with different number of columns: 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 111G20Rik%%% Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% Ascl2

Re: [R] help with read.csv() for files with different number of columns

2017-08-27 Thread Jim Lemon
Hi Ace, With tabs as separators: testdf<-read.table("test.txt",header=FALSE,fill=TRUE,sep="\t", col.names=paste("V",1:19,sep=""),stringsAsFactors=FALSE) Also note that I got the number of columns wrong the first time. Jim On Mon, Aug 28, 2017 at 12:56 PM, Fix Ace wrote: > Hi, Jim, > > Thank y

Re: [R] help with read.csv() for files with different number of columns

2017-08-27 Thread Jim Lemon
Hi Ace, As your example seems to have spaces as separators, testdf<-read.table("test.txt",header=FALSE,fill=TRUE, col.names=paste("V",1:14,sep=""),stringsAsFactors=FALSE) By specifying the number of columns with "col.names" and using "fill=TRUE" you can get a data frame with zero length strings w

Re: [R] help with read.csv() for files with different number of columns

2017-08-27 Thread Bert Gunter
Email a mess. Too hard for me to decipher, maybe also for others. If no response, send plain text, as requested by posting guide. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his

[R] help with read.csv() for files with different number of columns

2017-08-27 Thread Fix Ace via R-help
Dear R community, I have a text file (test.txt) with different number of columns: 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 111G20Rik%%% Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% Ascl2 Ifnar2 1700028J19Rik%%% Musk Nfe2l3 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c F