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 RCST 1 5 CSPP005 12/4/2007 1 1 LGM 0 6 CSPP005 12/4/2007 1 1 RGM 0 7 CSPP005 12/4/2007 1 1 Whole NA
The five levels are: ID->Date->Segment->Slice->Tract The observation variable is: Lesion What I want to do is (in pseudo code) if (any of the Tract (for a given ID, Date, Segment, and Slice), which( Lesion == 2) ) df [ for that particular (ID, Date,Segment, and slice) , which(Tract == Whole) ] $Lesion <- 2 else df [ for that particular (ID, Date,Segment, and slice) , which(Tract == Whole) ] $Lesion <- 0 I started with (don't know if this is the right path), Lesion2<-df[which(df$Lesion == 2),] Where.Lesion2<-unique(Lesion2[,1:4]) Whole<-subset(df, Tract == "Whole") But stuck at how to match the ID/Date/Segment/Slice from Where.Lesion2 to Whole. Regards Gordon ______________________________________________ R-help@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.