[R] select row based on highest value
LCOG1
jroll at lcog.org
Tue Feb 23 21:47:17 CET 2010
Please consider the following
#Data to use
Props<-c("p754921","p754921" ,"p754921","p75506" ,"p75506"
,"p75506","p75506","p75508","p75508","p75508","p75508","p75508")
TAZ<-c(38,37,37,171,171,282,171,46,46,169,169,169)
Area<-c(109828.04, 128134.71, 46469.57, 37160.21,
40080.50,344679.66,16972.28,
342309.558, 260906.870, 17014.659, 7285.706, 10936.316)
TazProperties..<-data.frame(Props,TAZ,Area)
t <- TazProperties..
v <- aggregate(t$Area, by=list(t$TAZ,t$Props), sum)
names(v) <- c("TAZ", "Prop", "area")
a<-tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)])
"a" returns:
p754921 p75506 p75508
37 38 37
and it should return
p754921 p75506 p75508
37 282 46
What am i doing wrong? Thanks
--
View this message in context: http://n4.nabble.com/select-row-based-on-highest-value-tp1566510p1566510.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list