Re: [R] gsub with regular expression

From: Allan Engelhardt <allane_at_cybaea.com>
Date: Fri, 25 Jun 2010 16:14:13 +0100

help("strsplit") is your friend, for example:

t <- c("2008/12/31 12:23:31 numero 343.233.233 Rodeo Vaca Ruido",

        "2010/02/01 02:35:31 palabra 111.111.222 abejorro Rodeo Vaca")

m <- do.call(rbind, strsplit(t, "[[:space:]]+"))  #  Matrix of all the data
v <- paste(m[, 1], m[, 2])  #  The vector
m <- m[,-c(1,2)]  #  The matrix

Hope this helps a little.

Allan

On 25/06/10 15:48, Sebastian Kruk wrote:
> If I have a text with 7 words per line and I would like to put first
> and second word joined in a vector and the rest of words one per
> column in a matrix how can I do it?
>
> First 2 lines of my text file:
> "2008/12/31 12:23:31 numero 343.233.233 Rodeo Vaca Ruido"
> "2010/02/01 02:35:31 palabra 111.111.222 abejorro Rodeo Vaca"
>
> Results:
>
> Vector:
> 2008/12/31 12:23:31
> 2010/02/01 02:35:31
>
> Matrix
> "numero" 343.233.233 "Rodeo" "Vaca" "Ruido"
> "palabra" 111.111.222 "abejorro" "Rodeo" "Vaca"
>
> Thks,
>
> Sebastian.
>
> ______________________________________________
> 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.
>



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. Received on Fri 25 Jun 2010 - 15:18:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jun 2010 - 15:20:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive