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

Re: [R] Help with read.csv

2011-03-10 Thread Giovanni Petris
Thanks to everybody who answered with suggestions (David Wolfskill, Stephen Sefick, Jim Holtman, Gabor Grothendieck, and Phil Spector). Beside the obvious end-of-the-day mixup ("int" in lieu of "integer"), I was not aware of the existence of a "NULL" class - which proved pretty useful in this cas

Re: [R] Help with read.csv

2011-03-09 Thread David Wolfskill
On Wed, Mar 09, 2011 at 04:32:29PM -0600, Giovanni Petris wrote: > > Hello, > > I have a file that looks like this: > > Date,Hour,DA_DMD,DMD,DA_RTP,RTP,, > 1/1/2006,1,3393.9,3412,76.65,105.04,, > 1/1/2006,2,3173.3,3202,69.20,67.67,, > 1/1/2006,3,3040.0,3051,69.20,77.67,, > 1/1/2006,4,2998.2,2979

Re: [R] Help with read.csv

2011-03-09 Thread Phil Spector
Giovanni - If you change "int" (which has no meaning in R) to "integer" in your second example, it should work. - Phil Spector Statistical Computing Facility Department o

Re: [R] Help with read.csv

2011-03-09 Thread Gabor Grothendieck
On Wed, Mar 9, 2011 at 5:32 PM, Giovanni Petris wrote: > > Hello, > > I have a file that looks like this: > > Date,Hour,DA_DMD,DMD,DA_RTP,RTP,, > 1/1/2006,1,3393.9,3412,76.65,105.04,, > 1/1/2006,2,3173.3,3202,69.20,67.67,, > 1/1/2006,3,3040.0,3051,69.20,77.67,, > 1/1/2006,4,2998.2,2979,67.32,69.10

Re: [R] Help with read.csv

2011-03-09 Thread jim holtman
Easiest is to use 'header = TRUE' and use the data from the file as the header (remove the skip=1). Let the system determine what it should be and then you can change it later. On Wed, Mar 9, 2011 at 5:32 PM, Giovanni Petris wrote: > > Hello, > > I have a file that looks like this: > > Date,Hour

[R] Help with read.csv

2011-03-09 Thread Giovanni Petris
Hello, I have a file that looks like this: Date,Hour,DA_DMD,DMD,DA_RTP,RTP,, 1/1/2006,1,3393.9,3412,76.65,105.04,, 1/1/2006,2,3173.3,3202,69.20,67.67,, 1/1/2006,3,3040.0,3051,69.20,77.67,, 1/1/2006,4,2998.2,2979,67.32,69.10,, 1/1/2006,5,3005.8,2958,65.20,68.34,, where the ',' is the separator a