Re: [R] paste first row string onto every string in column

2009-08-13 Thread Patrick Connolly
On Wed, 12-Aug-2009 at 09:06AM -0700, Jill Hollenbach wrote: | | Thanks so much everybody, this has been incredibly helpful--not only is my | immediate issue solved but I've learned a lot in the process. The lapply | solution is best for me, as I need flexibility to edit df's with varying |

Re: [R] paste first row string onto every string in column

2009-08-13 Thread Gene Leynes
I'm also a newbie, but I've been getting loads of utility out of the grep function and it's cousin gsub. Using asterisks are tricky because * often means anything of any length in a search pattern (e.g. delete *.* means delete all your files!). To find the literal * using grep you would need to

Re: [R] paste first row string onto every string in column

2009-08-12 Thread milton ruser
Hi Jill, Completely not elegant, but may be usefull. Of course other colleagues will solve this with 1 line command :-) cheers milton df-read.table(stdin(), head=T, sep=,) V1,V2,V3,V4 DPA1*,DPA1*,DPB1*,DPB1* 0103,0104,0401,0601 0103,0103,0301,0402 df.new-as.matrix(df) for (i in 2:dim(df)[1])

Re: [R] paste first row string onto every string in column

2009-08-12 Thread Patrick Connolly
On Tue, 11-Aug-2009 at 06:48PM -0700, Jill Hollenbach wrote: | | Hi, | I am trying to edit a data frame such that the string in the first line is | appended onto the beginning of each element in the subsequent rows. The data | looks like this: | | df | V1 V2 V3 V4 | 1 DPA1*

Re: [R] paste first row string onto every string in column

2009-08-12 Thread Benilton Carvalho
you could stick everything in a 1-liner, but that would make it less readable: myf - function(x){ tmp - as.character(x) c(tmp[1], paste(tmp[1], tmp[-1], sep=)) } df2 - as.data.frame(sapply(df, myf)) b On Aug 12, 2009, at 3:39 AM, milton ruser wrote: Hi Jill, Completely not elegant,

Re: [R] paste first row string onto every string in column

2009-08-12 Thread Don MacQueen
Let's start with something simple and relatively easy to understand, since you're new to this. First, here's an example of the core of the idea: paste('a',1:4) [1] a 1 a 2 a 3 a 4 Make it a little closer to your situation: paste('a*',1:4, sep='') [1] a*1 a*2 a*3 a*4 Sometimes it helps

Re: [R] paste first row string onto every string in column

2009-08-12 Thread Jill Hollenbach
Thanks so much everybody, this has been incredibly helpful--not only is my immediate issue solved but I've learned a lot in the process. The lapply solution is best for me, as I need flexibility to edit df's with varying numbers of columns. Now, one more question: after appending the string

[R] paste first row string onto every string in column

2009-08-11 Thread Jill Hollenbach
Hi, I am trying to edit a data frame such that the string in the first line is appended onto the beginning of each element in the subsequent rows. The data looks like this: df V1 V2 V3 V4 1 DPA1* DPA1* DPB1* DPB1* 2 0103 0104 0401 0601 3 0103 0103 0301 0402 . . and what