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]]
? 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.
Does this give you what you want:> x <- read.table(textConnection("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"), as.is=TRUE)> # remove parenthesis > x$V1 <- gsub("[()]", "", x$V1) > > > xV1 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 Sun, Jan 18, 2009 at 12:13 PM, oscar linares <winsaam at gmail.com> 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Dear Rxperts, I would like to convert the following: Study Study.Name Parameter Dest Src Form Value Min Max FSD 1 NT_1-0BF K(03) 03 A 0.12851 0.00000E+00 10000. 0.41670E-01 1 NT_1-0BF L(00,03) 00 03 D 0.36577 1 NT_1-0BF L(00,02) 00 02 D 0.90000 1 NT_1-0BF L(00,04) 00 04 D 0.90000 1 NT_1-0BF P(01) 01 A 0.36577 0.00000E+00 100.00 0.36880E-01 1 NT_1-0BF P(02) 02 A 28.269 0.00000E+00 100.00 0.58489E-01 1 NT_1-0BF P(03) 03 A 68.144 10.000 1000.0 0.27806E-01 1 NT_1-0BF P(05) 05 D 0.90000 1 NT_1-0BF P(31) 31 D 26.316 1 NT_1-0BF P(32) 32 D 29.483 1 NT_1-0BF P(22) 22 D 7.7813 Study Study.Name Parameter Dest Src Form Value Min Max FSD 1 NT_1-1BF K(03) 03 A 0.12852 0.00000E+00 10000. 0.39727E-01 1 NT_1-1BF L(00,03) 00 03 D 0.36577 1 NT_1-1BF L(00,02) 00 02 D 0.90000 1 NT_1-1BF L(00,04) 00 04 D 0.90000 1 NT_1-1BF P(01) 01 A 0.36577 0.00000E+00 100.00 0.35166E-01 1 NT_1-1BF P(02) 02 A 28.280 0.00000E+00 100.00 0.55760E-01 1 NT_1-1BF P(03) 03 A 68.134 10.000 1000.0 0.26508E-01 1 NT_1-1BF P(05) 05 D 0.90000 1 NT_1-1BF P(22) 22 D 7.7811 Study Study.Name Parameter Dest Src Form Value Min Max FSD 1 NT_1-2BF K(03) 03 A 0.12851 0.00000E+00 10000. 0.90167E-01 1 NT_1-2BF L(00,03) 00 03 D 0.36575 1 NT_1-2BF L(00,02) 00 02 D 0.90000 1 NT_1-2BF L(00,04) 00 04 D 0.90000 1 NT_1-2BF P(01) 01 A 0.36575 0.00000E+00 100.00 0.79794E-01 1 NT_1-2BF P(02) 02 A 23.890 0.00000E+00 100.00 0.13385 1 NT_1-2BF P(03) 03 A 76.297 10.000 1000.0 0.68931E-01 1 NT_1-2BF P(05) 05 D 0.90000 1 NT_1-2BF P(22) 22 D 7.7815 To look like the following stata output | study studyn~e K3 P1 P2 P3 P5 P11 P23 P31 P32 P33 | |------------------------------------------------------------------------------------------------------| 1. | 1 NT_16 .125 .35 35.903 8.6815 .83195 58 .13793 26.316 4.7181 13.211 | 2. | 2 NT_1 .125 .35 23.173 9.4882 .75125 66.7 .11994 26.316 4.0427 11.32 | 3. | 3 NT_2 .125 .35 48.229 7.1296 .68354 66.7 .11994 26.316 4.9101 13.748 | 4. | 4 NT_3 .125 .35 8.0027 15.967 1.1438 80 .1 26.316 .37137 1.0398 | 5. | 5 NT_4 .125 .35 24.468 4.4256 .65408 40 .2 26.316 2.1901 6.1322 | |------------------------------------------------------------------------------------------------------| Any suggestions for doing this in R? Many thanks in advance for your help. -- Oscar Oscar A. Linares Molecular Medicine Unit Bolles Harbor Monroe, Michigan [[alternative HTML version deleted]]
Although the message is rather unreadable, I guess you want to look at ?reshape. Uwe Ligges oscar linares wrote:> Dear Rxperts, > > I would like to convert the following: > > Study Study.Name Parameter Dest Src Form Value Min > Max FSD > 1 NT_1-0BF K(03) 03 A 0.12851 0.00000E+00 10000. > 0.41670E-01 > 1 NT_1-0BF L(00,03) 00 03 D 0.36577 > 1 NT_1-0BF L(00,02) 00 02 D 0.90000 > 1 NT_1-0BF L(00,04) 00 04 D 0.90000 > 1 NT_1-0BF P(01) 01 A 0.36577 0.00000E+00 100.00 > 0.36880E-01 > 1 NT_1-0BF P(02) 02 A 28.269 0.00000E+00 100.00 > 0.58489E-01 > 1 NT_1-0BF P(03) 03 A 68.144 10.000 1000.0 > 0.27806E-01 > 1 NT_1-0BF P(05) 05 D 0.90000 > 1 NT_1-0BF P(31) 31 D 26.316 > 1 NT_1-0BF P(32) 32 D 29.483 > 1 NT_1-0BF P(22) 22 D 7.7813 > Study Study.Name Parameter Dest Src Form Value Min > Max FSD > 1 NT_1-1BF K(03) 03 A 0.12852 0.00000E+00 10000. > 0.39727E-01 > 1 NT_1-1BF L(00,03) 00 03 D 0.36577 > 1 NT_1-1BF L(00,02) 00 02 D 0.90000 > 1 NT_1-1BF L(00,04) 00 04 D 0.90000 > 1 NT_1-1BF P(01) 01 A 0.36577 0.00000E+00 100.00 > 0.35166E-01 > 1 NT_1-1BF P(02) 02 A 28.280 0.00000E+00 100.00 > 0.55760E-01 > 1 NT_1-1BF P(03) 03 A 68.134 10.000 1000.0 > 0.26508E-01 > 1 NT_1-1BF P(05) 05 D 0.90000 > 1 NT_1-1BF P(22) 22 D 7.7811 > Study Study.Name Parameter Dest Src Form Value Min > Max FSD > 1 NT_1-2BF K(03) 03 A 0.12851 0.00000E+00 10000. > 0.90167E-01 > 1 NT_1-2BF L(00,03) 00 03 D 0.36575 > 1 NT_1-2BF L(00,02) 00 02 D 0.90000 > 1 NT_1-2BF L(00,04) 00 04 D 0.90000 > 1 NT_1-2BF P(01) 01 A 0.36575 0.00000E+00 100.00 > 0.79794E-01 > 1 NT_1-2BF P(02) 02 A 23.890 0.00000E+00 100.00 > 0.13385 > 1 NT_1-2BF P(03) 03 A 76.297 10.000 1000.0 > 0.68931E-01 > 1 NT_1-2BF P(05) 05 D 0.90000 > 1 NT_1-2BF P(22) 22 D 7.7815 > > To look like the following stata output > > | study studyn~e K3 P1 P2 P3 P5 P11 > P23 P31 P32 P33 | > > |------------------------------------------------------------------------------------------------------| > 1. | 1 NT_16 .125 .35 35.903 8.6815 .83195 58 > .13793 26.316 4.7181 13.211 | > 2. | 2 NT_1 .125 .35 23.173 9.4882 .75125 66.7 > .11994 26.316 4.0427 11.32 | > 3. | 3 NT_2 .125 .35 48.229 7.1296 .68354 66.7 > .11994 26.316 4.9101 13.748 | > 4. | 4 NT_3 .125 .35 8.0027 15.967 1.1438 > 80 .1 26.316 .37137 1.0398 | > 5. | 5 NT_4 .125 .35 24.468 4.4256 .65408 > 40 .2 26.316 2.1901 6.1322 | > > |------------------------------------------------------------------------------------------------------| > > Any suggestions for doing this in R? > > Many thanks in advance for your help. >