[R] Importing files
jim holtman
jholtman at gmail.com
Mon Mar 19 03:43:25 CET 2012
The file that you set was readable. The majority of the fields were
comma separated, so I use the comma as the field separator in the
'read.table'. The 'tab' character appears to be the separator between
the date and time and this does not prevent reading in the data, or
parsing it later. So here is what I got:
> x <- read.table("C:\\temp\\2196001_CALBOR_2008_Veneguera 0.act"
+ , sep = ','
+ , as.is= TRUE
+ )
> str(x)
'data.frame': 29 obs. of 4 variables:
$ V1: chr "ok" "ok" "ok" "ok" ...
$ V2: chr "05/06/07 19:08:00" "05/06/07 19:17:59" "05/06/07
19:27:59" "05/06/07 19:37:59" ...
$ V3: num 39239 39239 39239 39239 39239 ...
$ V4: int 9 1 0 0 0 0 0 0 0 0 ...
> head(x)
V1 V2 V3 V4
1 ok 05/06/07 19:08:00 39238.80 9
2 ok 05/06/07 19:17:59 39238.80 1
3 ok 05/06/07 19:27:59 39238.81 0
4 ok 05/06/07 19:37:59 39238.82 0
5 ok 05/06/07 19:47:59 39238.82 0
6 ok 05/06/07 19:57:59 39238.83 0
>
so the data is reasonable and you can work with. So what was the
problem? Do you want the time converted to POSIXct so you can use
it? Do you just want to extract the value (V4)?
So I don't see any problem in processing the data.
2012/3/18 Santiago Guallar <sguallar at yahoo.com>:
> Thank you Jim.
> Here the original format and its conversion to txt.
>
> Santi
>
> From: jim holtman <jholtman at gmail.com>
> To: Santiago Guallar <sguallar at yahoo.com>
> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Sunday, March 18, 2012 10:59 PM
> Subject: Re: [R] Importing files
>
> You attachment never made it through. Try sending it as '.txt' file.
> If the file is using both tabs and commas on the same line, then you
> may have to use 'readLines' to read it in, and then 'strsplit' to
> split out the different elements.
>
> On Sun, Mar 18, 2012 at 4:13 PM, Santiago Guallar <sguallar at yahoo.com>
> wrote:
>> Hello,
>> I'm trying to import into R files that contain data downloaded from logger
>> devices as files with the following formats:
>> .act
>> .lig
>> .trj
>> .trn
>> These files are essentially text files but use both tabs and commas as
>> separators.
>> I've tried the function scan:
>>
>> 1) scan("filename.act", what=character(0)) returns only two columns from
>> the original 5
>> 2) scan("copia.act", what=character(0),sep=",") returns three columns but
>> puts the original fifth one in the next row
>>
>> Attached a sample file with five fields. How can I get one field per
>> column?
>>
>> Thank you for your help
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
More information about the R-help
mailing list