On Sep 8, 2009, at 12:00 PM, Lauri Nikkinen wrote:
Ok, I think that I have to give up and try to get this data separated
by some char. It seem pretty much impossible to separate those fields.
Thanks for your help and efforts.
The solution that Henrique offered seems to be a complete one:
rea
Ok, I think that I have to give up and try to get this data separated
by some char. It seem pretty much impossible to separate those fields.
Thanks for your help and efforts.
-L
2009/9/8 Lauri Nikkinen :
> This is the file (see the attachment) that represents the problem I'm
> facing with the ori
This is the file (see the attachment) that represents the problem I'm
facing with the original file. I'm looking for some generic way to
solve this problem. Thank you for your time.
-L
2009/9/8 Barry Rowlingson :
> On Tue, Sep 8, 2009 at 1:52 PM, Lauri Nikkinen wrote:
>
>> But this is not the sol
On Tue, Sep 8, 2009 at 1:52 PM, Lauri Nikkinen wrote:
> But this is not the solution I was looking for. Thanks.
I think the only way you'll get the solution you are looking for is
if you can let us have a copy of the original input file, or at least
the first few lines - and not pasted into an e
Try this:
read.table(textConnection(gsub("([0-9]+)", ";\\1;", x)), sep = ";")
On Tue, Sep 8, 2009 at 9:52 AM, Lauri Nikkinen wrote:
> Thanks Petr, I tried something like this
>
> > con <- file("C:temppi.txt", "r", blocking = FALSE)
> > g <- readLines(con)
> > close(con)
> >
> > sta <- c(1, 3, 5,
Thanks Petr, I tried something like this
> con <- file("C:temppi.txt", "r", blocking = FALSE)
> g <- readLines(con)
> close(con)
>
> sta <- c(1, 3, 5, 19)
> sto <- c(2, 4, 18, 100)
> do.call("rbind", lapply(g, function(x) substring(x, sta, sto)))
[,1] [,2] [,3] [,4]
[1,] "DF" "12"
On Tue, Sep 08, 2009 at 03:21:53PM +0300, Lauri Nikkinen wrote:
> This data is from database and the maximum length of a field is
> defined. I mean that every column has a maximum length and I want to
> use this maximum length as a separator. So if one "cell" in that
> column is shorter than the ma
Hi
what about reading each line by readLine and then split it to desired
portions?
x<-paste(letters, collapse="")
substring(x, c(1,3,5),c(2,4,15))
Regards
Petr
r-help-boun...@r-project.org napsal dne 08.09.2009 14:21:53:
> This data is from database and the maximum length of a field is
> def
Thanks for the suggestion, but I don't have an access to this
database, I just got this messy file.
-L
2009/9/8 Duncan Murdoch :
> On 9/8/2009 8:21 AM, Lauri Nikkinen wrote:
>>
>> This data is from database and the maximum length of a field is
>> defined. I mean that every column has a maximum le
On Tue, Sep 08, 2009 at 02:53:11PM +0300, Lauri Nikkinen wrote:
> I have a text file similar to this (separated by spaces):
>
> x <- "DF12 This is an example 1 This
> DF12 This is an 1232 This is
> DF14 This is 12334 This is an
> DF15 This 23 This is an example
> "
>
> and I know the field length
On 9/8/2009 8:21 AM, Lauri Nikkinen wrote:
This data is from database and the maximum length of a field is
defined. I mean that every column has a maximum length and I want to
use this maximum length as a separator. So if one "cell" in that
column is shorter than the maximum, "cell" should be pad
This bears no relationship to what you were first asking. It look
like you want to split the leading 4 characters into two groups of two
and then split the remaining data into three parts based on numerics
in the middle. Is this correct?
On Tue, Sep 8, 2009 at 8:15 AM, Lauri Nikkinen wrote:
> Su
This data is from database and the maximum length of a field is
defined. I mean that every column has a maximum length and I want to
use this maximum length as a separator. So if one "cell" in that
column is shorter than the maximum, "cell" should be padded with white
spaces or something like that.
I don't think you described your problem precisely.
You implied that you wanted the field lengths to be
(2,2,18,5,18) -- which is what you got with read.fwf --
but it looks like what you meant is something more like:
field 1: first two characters
field 2: characters 3-4
field 3: all alphabeti
Sure, here you go
structure(list(V1 = structure(c(1L, 1L, 1L, 1L), .Label = "DF", class
= "factor"),
V2 = c(12L, 12L, 14L, 15L), V3 = structure(c(4L, 3L, 2L,
1L), .Label = c("This", "This is", "This is an", "This is an example"
), class = "factor"), V4 = c(1L, 1232L, 12334L, 23L), V5 =
On 9/8/2009 8:07 AM, Lauri Nikkinen wrote:
Thanks, I tried it but I got
varlength <- c(2, 2, 18, 5, 18)
read.fwf("c:temppi.txt", widths=varlength)
V1 V2 V3V4 V5
1 DF 12 This is an exampl e 1 T his
2 DF 12 This is an 1232 T his is
3 DF 14 This is 12334 Thi s is
Can you post how you would like it.
On Tue, Sep 8, 2009 at 8:07 AM, Lauri Nikkinen wrote:
> Thanks, I tried it but I got
>
>> varlength <- c(2, 2, 18, 5, 18)
>> read.fwf("c:temppi.txt", widths=varlength)
> V1 V2 V3 V4 V5
> 1 DF 12 This is an exampl e 1 T his
> 2 DF 12 This
Thanks, I tried it but I got
> varlength <- c(2, 2, 18, 5, 18)
> read.fwf("c:temppi.txt", widths=varlength)
V1 V2 V3V4 V5
1 DF 12 This is an exampl e 1 T his
2 DF 12 This is an 1232 T his is
3 DF 14 This is 12334 Thi s is an
4 DF 15 This 23 This is a n exa mple
On 9/8/2009 7:53 AM, Lauri Nikkinen wrote:
I have a text file similar to this (separated by spaces):
x <- "DF12 This is an example 1 This
DF12 This is an 1232 This is
DF14 This is 12334 This is an
DF15 This 23 This is an example
"
and I know the field lengths of each variable (there is 5 variab
On Tue, Sep 8, 2009 at 12:53 PM, Lauri Nikkinen wrote:
> I have a text file similar to this (separated by spaces):
>
> x <- "DF12 This is an example 1 This
> DF12 This is an 1232 This is
> DF14 This is 12334 This is an
> DF15 This 23 This is an example
> "
>
> and I know the field lengths of each v
I have a text file similar to this (separated by spaces):
x <- "DF12 This is an example 1 This
DF12 This is an 1232 This is
DF14 This is 12334 This is an
DF15 This 23 This is an example
"
and I know the field lengths of each variable (there is 5 variables in
this data set), which are:
varlength
21 matches
Mail list logo