[R] data management

David Winsemius dwinsemius at comcast.net
Sun Jan 18 20:23:15 CET 2009


? gsub

 >
 > gsub("\\(|\\)", "", var)


You can then read.table on a textConnection.

 > read.table(textConnection(gsub("\\(|\\)", "", var) ))
   V1 V2
1 p1 10
2 p1  3
3 p1  4
4 p2 20
5 p2 30
6 p2 40
7 p3  4
8 p3  1
9 p1  2

On Jan 18, 2009, at 12:13 PM, oscar linares wrote:

> Dear Rxperts,
>
> I have a varaibles data file that looks like this
>
> p(1) 10
> p(1) 3
> p(1) 4
> p(2) 20
> p(2) 30
> p(2) 40
> p(3) 4
> p(3) 1
> p(1) 2
>
> I cannot process these data with R because it does not like the  
> parentheses.
> How can I get these to look like:
>
> p1 10
> p1 3
> p1 4
> p2 20
> p2 30
> p2 40
> p3 4
> p3 1
> p3 2
>
> The data is in a tab delimited text file and I want to get it into a
> data.frame().
>
> Many thanks in advance.
>
> OAL
> p1
> p1
>
> -- 
> Oscar
> Oscar A. Linares
> Molecular Medicine Unit
> Bolles Harbor
> Monroe, Michigan
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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