[R-sig-Geo] simple help to calculate max statistic in data.frame

Tom Gottfried tom.gottfried at wzw.tum.de
Sun Mar 8 19:26:00 CET 2009


Hi Gianni,

when you combine the information given in chapter 2.7 (especially the  
part about logical index vectors) and chapter 5.2 (note that a  
data.frame here acts like an array with two dimensions) of "An  
Introduction to R", you see that you can do that with logical index  
vectors (e.g. looping over the values in your column "ID").  
Furthermore you can consider using `subset()'.

Hope this helps.

Regards,
Tom

> Date: Fri, 6 Mar 2009 13:08:25 +0100
> From: gianni lavaredo <gianni.lavaredo at gmail.com>
> Subject: [R-sig-Geo] simple help to calculate max statistic in
> 	data.frame
> To: r-sig-geo at stat.math.ethz.ch
> Message-ID:
> 	<518dff330903060408u660639c0w334c57442efb393c at mail.gmail.com>
> Content-Type: text/plain
>
> Thanks for help and attention
>
> I have a data.frame "sample" in shape-file like this
>
> ID; pH
> 1;3.4
> 1;3.8
> 1;3.9
> 4;5.5
> 4;5.9
> 4;5.8
> 5;7.1
> 5;7.5
> 5;7.6
> 5;7.7
> 5;7.8
> 5;7.9
>
> I wish to extract the max(pH) of ID = 1, after max(pH) of ID = 2,  
> etc. etc.
>
> I tryed the code
>
> sample <- readOGR(".", "sample")
> max(sample$pH) #to obtain the max of pH
> max(sample$ph[c(1), ] #not run
>
> thanks
> Gianni
>
> 	[[alternative HTML version deleted]]
>



More information about the R-sig-Geo mailing list