[R] Select first element of each factor and convert to NA

PIKAL Petr petr.pikal at precheza.cz
Fri Mar 1 08:42:41 CET 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Cesar Terrer
> Sent: Friday, March 01, 2013 4:21 AM
> To: r-help at r-project.org
> Subject: [R] Select first element of each factor and convert to NA
> 
> Hi all,
> 
> 
> 
> I have a dataframe of the following type:
> 
> 
> 
> Day        Place     dendrometer    max
> 
> 1              1                              1              4684
> 
> 2              1                              1              4831
> 
> ..
> 
> 1              1                              2              2486
> 
> 2              1                              2              2596
> 
> .
> 
> 1              2                              1              6987
> 
> 2              2                              1              6824
> 
> 
> 
> I need  the first element of each dendrometer  as NA, so every time R
> calculates "max" for a new dendrometer (independently of the place),
> starts with NA,  like this:
> 
> 
> 
> Day        Place     dendrometer    max
> 
> 1              1                              1              NA
> 
> 2              1                              1              4831
> 
> ..
> 
> 1              1                              2              NA
> 
> 2              1                              2              2596
> 
> .
> 
> 1              2                              1              NA
> 
> 2              2                              1              6824
> 

Just as a curiosity, do you want to change max value for a Day 1 to NA? If yes, 

DF$max[DF$Day==1] <- NA

shall work.

> 
> 
> Could you also let me know I could calculate MEAN of the max column for
> each dendrometer within each ring (sapply, aggregate?) instead of
> calculating mean for the entire max column?

?aggregate or maybe ?ave

Regards
Petr

> 
> 
> 
> Thanks!
> 
> 
> 
> 
> 	[[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.



More information about the R-help mailing list