[R] code rows depending on the value of other rows in multilevel dataframe

2010-03-13 Thread Junqian Gordon Xu
I have a multilevel dataframe (df): ID Date Segment Slice Tract Lesion 1 CSPP005 12/4/2007 1 1 LCST 0 2 CSPP005 12/4/2007 1 1 LPC 2 3 CSPP005 12/4/2007 1 1 RPC 3 4 CSPP005 12/4/2007 1 1

Re: [R] code rows depending on the value of other rows in multilevel dataframe

2010-03-13 Thread jim holtman
It is not entirely clear what type of transformation you are trying to do. Can you provide some sample data and then show what you would expect the output to look like; make sure the data covers all the cases you want to transform. On Sat, Mar 13, 2010 at 8:54 PM, Junqian Gordon Xu

Re: [R] code rows depending on the value of other rows in multilevel dataframe

2010-03-13 Thread Junqian Gordon Xu
Hi, In the example given below, I want to code the Lesion in the 7th row as 2 because the 2nd row has a Lesion value of 2. ID Date Segment Slice Tract Lesion 7 CSPP005 12/4/2007 1 1 Whole2 Otherwise (if there is no lesion value of 2 in row 1-6), I

Re: [R] code rows depending on the value of other rows in multilevel dataframe

2010-03-13 Thread Junqian Gordon Xu
merge(Whole,Where.Lesion2) gives the intersections (ID/Date/Segment/Slice, i.e. the first 4 columns), except that the merge function drops the original row.names in the dataframe Whole. Now, the question evolves to finding row.names of one data frame that matches any of the rows in another

Re: [R] code rows depending on the value of other rows in multilevel dataframe

2010-03-13 Thread jim holtman
Try this: x - read.table(textConnection( +ID Date Segment Slice Tract Lesion + CSPP005 12/4/2007 1 1 LCST 0 + CSPP005 12/4/2007 1 1 LPC 2 + CSPP005 12/4/2007 1 1 RPC 3 + CSPP005 12/4/2007 1