[R] cbind and mean by week

Felipe Carrillo mazatlanmexico at yahoo.com
Wed Mar 26 04:18:56 CET 2008


 Hi:
 I have been able to finally crunch my data by
importing it by week(thank you all for your help),but
here we go again..
 Now I'am trying to do it for the the whole year.
Since the
 dataset is huge I'm only making a 3 weeks dataframe.
- I want to get the mean of pd by week
- I want to count the number of days by week and bind
it to the existing dataframe(x)
- I want to remove the NA's by week and bind another
column counting the rows after the NA's are removed.
 Don't think that I'am crazy but I need those fields
 for my annual report. I was trying to use some of
 the functions below but nothing seems to work..One
 of these days I'll be an R pro(we'll see about that)
 Thanks
 
week<-c(28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30)
td<-c(0.015,0.012,NA,0.015,NA,0.014,0.014,0.013,0.013,0.013,0.013,NA,0.010,0.013,0.015,0.011,0.014,0.014,0.014,0.014,0.016)
pd<-c(0,0,NA,80,NA,45,223,228,224,488,525,NA,80,417,413,373,914,213,651,521,979)
 x<-data.frame(week,td,pd)
 x
  pmean<- tapply(x[,3], x$week, mean)
    pdmean
    pdmean<- data.frame(pmean)
    pdmean
 xweek <- aggregate(x, list(x$week), mean)
xweek

 Felipe D. Carrillo
  Fishery Biologist
  Department of the Interior
  US Fish & Wildlife Service
  California, USA



      ____________________________________________________________________________________
Be a better friend, newshound, and



More information about the R-help mailing list