[R] ?to calculate sth for groups defined between points in one variable (string), / value separating/ spliting variable into groups by i.e. between start, NA, NA, stop1, start2, NA, stop2

From: Eugeniusz Kaluza <Eugeniusz.Kaluza_at_polsl.pl>
Date: Thu, 24 Jun 2010 13:18:36 +0200

Dear useRs,

Thanks for any advices

# I do not know where are the examples how to mark groups
# based on signal occurence in the additional variable: cf. variable c2,
# How to calculate different calculations for groups defined by (split by occurence of c2 characteristic data)

#First example of simple data
#mexample 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

c0<-rbind( 1,      2 , 3, 4,      5, 6, 7, 8, 9,10,11,      12,13,14,15,16,17     )
c1<-rbind(10,     20 ,30,40,     50,10,60,20,30,40,50,      30,10, 0,NA,20,10.3444)
c2<-rbind(NA,"Start1",NA,NA,"Stop1",NA,NA,NA,NA,NA,NA,"Start2",NA,NA,NA,NA,"Stop2") c2

# preparation of form for explaining further needed result (next 3 lines are not needed indeed, they are only to explain how to obtain final result
 c3<-rbind(NA,"Start1","Start1","Start1","Start1","Start2","Start2","Start2","Start2","Start2","Start2","Start2","Start2","Start2","Start2","Start2","Start2")  c4<-rbind(NA, "Stop1", "Stop1", "Stop1", "Stop1", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2", "Stop2")  C.df<-data.frame(cbind(c0,c1,c2,c3,c4))  colnames(C.df)<-c("c0","c1","c2","c3","c4")  C.df$c5<-paste(C.df$c3,C.df$c4,sep="-")  C.df


 # needed result
# for Stat1-Stop1: mean(20,30,40,50)
# for Stat2-Stop2: mean(c(10,60,20,30,40,50,30,10,0,NA,20,10.3444), na.rm=T)

         c1     c3    c4           c5
         20  Start1 Stop1 Start1-Stop1

   25.48585 Start2 Stop2 Start2-Stop2

# for Stat1-Stop1: sum(20,30,40,50)
# for Stat2-Stop2: sum(c(10,60,20,30,40,50,30,10,0,NA,20,10.3444), na.rm=T)

         c1     c3    c4           c5
        140  Start1 Stop1 Start1-Stop1

   280.3444 Start2 Stop2 Start2-Stop2

# for Stat1-Stop1: max(20,30,40,50)
# for Stat2-Stop2: max(c(10,60,20,30,40,50,30,10,0,NA,20,10.3444), na.rm=T)

         c1     c3    c4           c5
        50  Start1 Stop1 Start1-Stop1
        60  Start2 Stop2 Start2-Stop2

# place of max (in Start1-Stop1: 4 th element in gruop Start1-Stop1
# place of max (in Start1-Stop1: 2 nd element in gruop Start1-Stop1

        c0     c3    c4           c5
         4  Start1 Stop1 Start1-Stop1
         2  Start2 Stop2 Start2-Stop2

Thanks for any suggestion,

        [[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. Received on Thu 24 Jun 2010 - 11:21:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jun 2010 - 13:40:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive