Re: [R] How to read only specified columns from a data file

2011-03-16 Thread Luis Ridao
Thanks Sarah. Best, Luis On Wed, Mar 16, 2011 at 1:19 PM, Sarah Goslee wrote: > On Wed, Mar 16, 2011 at 9:07 AM, Luis Ridao wrote: >> This is my code: >> >> mycols <- rep(NULL, 430) ; mycols[c(1,3:5)] <- rep("numeric", 4) ; >> mycols[c(2)] <- rep("character",1) > > rep(NULL, 430) does not give

Re: [R] How to read only specified columns from a data file

2011-03-16 Thread Sarah Goslee
On Wed, Mar 16, 2011 at 9:07 AM, Luis Ridao wrote: > This is my code: > > mycols <- rep(NULL, 430) ; mycols[c(1,3:5)] <- rep("numeric", 4) ; > mycols[c(2)] <- rep("character",1) rep(NULL, 430) does not give you a vector of length 430; it gives you a NULL vector, and at the end of this process myc

Re: [R] How to read only specified columns from a data file

2011-03-16 Thread David Winsemius
On Mar 16, 2011, at 8:13 AM, Sarah Goslee wrote: read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was disc

Re: [R] How to read only specified columns from a data file

2011-03-16 Thread Luis Ridao
This is my code: mycols <- rep(NULL, 430) ; mycols[c(1,3:5)] <- rep("numeric", 4) ; mycols[c(2)] <- rep("character",1) inp <- read.table(myfile, skip=2, colClasses=mycols,fill=T) head(inp) Best, Luis On Wed, Mar 16, 2011 at 1:03 PM, David Winsemius wrote: > > On Mar 16, 2011, at 8:13 AM, Sarah

Re: [R] How to read only specified columns from a data file

2011-03-16 Thread Sarah Goslee
read.table() looks at the first five rows when determining how many columns there are. If there are more columns in row 7 and you do not specify that in the read.table() command directly, they will be wrapped to the next row. This was discussed on the list within the last couple weeks. Sarah On

Re: [R] How to read only specified columns from a data file

2011-03-16 Thread Luis Ridao
David, Thanks for your tip but it seems I'm having problems with the number of columns R manages to read in. Below it s an example of the data read in: > inp[1:20,] V1 V2V3 V4 V5 V6 V7 V8 V9 1 1. log_fy_coff -1.007600 0.119520 1. NA

Re: [R] How to read only specified columns from a data file

2011-03-15 Thread David Winsemius
On Mar 15, 2011, at 1:11 PM, wrote: I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab <- read.

Re: [R] How to read only specified columns from a data file

2011-03-15 Thread rex.dwyer
I think you need to read an introduction to R. For starters, read.table returns its results as a value, which you are not saving. The probable answer to your question: Read the whole file with read.table, and select columns you need, e.g.: tab <- read.table(myfile, skip=2)[,1:5] -Original Mes