[R] Reading files with varying number of columns
Tim Clark
mudiver1200 at yahoo.com
Sun Jul 18 21:39:01 CEST 2010
Thanks for the suggestion. I had read "fill" but didn't pick up on the
details. It only uses the first five columns to determine column dimensions, so
it ignored my last two columns. Specifying "col.names" with fill=TRUE did the
trick!
Aloha,
Tim
----- Original Message ----
From: Uwe Ligges <ligges at statistik.tu-dortmund.de>
To: Tim Clark <mudiver1200 at yahoo.com>
Cc: r-help at r-project.org
Sent: Sun, July 18, 2010 6:03:47 AM
Subject: Re: [R] Reading files with varying number of columns
See argument "fill" in ?read.table
Uwe Ligges
On 18.07.2010 12:14, Tim Clark wrote:
> Dear R list,
> I am trying to read files with a varying number of columns and can't figure
out
> how to get them in the proper format. Some rows have five value and some have
> seven. Is there a way to read them in so that two empty columns are added to
> every row that has only five values? An example of the data follows. Thanks!
> Tim
>
>> 46,B,00301,2004-02-03,11:59:16
>> 46,B,00301,2004-02-03,12:03:43
>> 46,B,00301,2004-02-03,12:39:17
>> 46,B,00301,2004-02-03,23:07:28
>> 43,C,00232,2004-02-04,07:39:57,-1.5,meters
>> 44,A,00230,2004-02-04,07:44:59
>> 44,A,00230,2004-02-04,07:46:19
>> 44,A,00230,2004-02-04,07:48:24
>> 44,A,00230,2004-02-04,07:49:12
>> 43,C,00232,2004-02-04,07:53:08,2.5,meters
>> 44,A,00230,2004-02-04,07:54:34
>> 44,A,00230,2004-02-04,07:55:08
>> 43,C,00232,2004-02-04,07:56:18,2.9,meters
>> 43,C,00232,2004-02-04,07:56:39,2.5,meters
>> 46,B,00301,2004-02-04,08:00:49
>> 43,C,00232,2004-02-04,08:02:12,-1.1,meters
>> 43,C,00232,2004-02-04,08:04:01,2.2,meters
>> 43,C,00232,2004-02-04,08:04:26,3.3,meters
>> 43,C,00232,2004-02-04,08:40:26,2.9,meters
>> 43,C,00232,2004-02-04,08:41:04,-2.2,meters
>> 43,C,00232,2004-02-04,08:42:44,2.2,meters
>> 43,C,00232,2004-02-04,08:44:31,2.9,meters
>> 44,A,00231,2004-02-04,09:04:43
>> 44,A,00231,2004-02-04,09:10:30
>> 44,A,00231,2004-02-04,09:12:08
>> 44,A,00231,2004-02-04,09:13:32
>> 44,A,00231,2004-02-04,09:14:06
>> 43,C,00232,2004-02-04,09:18:24,0.4,meters
>> 43,C,00232,2004-02-04,09:20:13,2.5,meters
>> 44,A,00231,2004-02-04,09:21:04
>> 44,A,00231,2004-02-04,09:22:53
>> 44,A,00231,2004-02-04,09:25:32
>> 44,A,00231,2004-02-04,09:29:31
>> 44,A,00231,2004-02-04,09:30:05
>> 43,C,00232,2004-02-04,09:53:25,2.5,meters
>> 43,C,00232,2004-02-04,09:53:53,1.5,meters
>> 46,B,00301,2004-02-04,22:16:24
>> 46,B,00301,2004-02-04,22:19:32
>> 46,B,00258,2004-02-04,23:44:01
>> 46,B,00258,2004-02-04,23:44:28
>
>
> Tim Clark
>
> Marine Ecologist
> National Park of American Samoa
> Pago Pago, American Samoa 96799
>
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list