Good day all, I am having an issue coercing my data. Below i have some data on taxlots and an associated TAZ(transportation analsysi zone) that each property is within. The main issue is that some properties cross TAZ boundaries so i need to make a decision as to which TAZ the property belongs too, i would like to do this based on the area of the Property and ultimately assign the the property to the TAZ in which the majority or the most of the area is within. For instance in the data below: Property p754921 is in two TAZs, 38 and 37. Since the property is mostly in 37 i would like to assign this value to the list of properties(Props) so that MultiTazProperties_ goes from $p754921 [1] 38 37 37 $p75506 [1] 171 171 282 171 $p75508 [1] 46 46 169 169 169 to.... $p754921 [1] 37 $p75506 [1] 282 $p75508 [1] 46 Props TAZ Area 1 p754921 38 109828.040 2 p754921 37 128134.710 3 p754921 37 46469.570 4 p75506 171 37160.210 5 p75506 171 40080.500 6 p75506 282 344679.660 7 p75506 171 16972.280 8 p75508 46 342309.558 9 p75508 46 260906.870 10 p75508 169 17014.659 11 p75508 169 7285.706 12 p75508 169 10936.316>#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) MultiTazProperties_<-tapply(TAZ , Props, function(x) x) MultiTazArea_<-tapply(Area , Props, function(x) x) Hope my inquiry is clear. Thanks -- View this message in context: http://n4.nabble.com/Selecting-single-TAZ-based-on-area-proportion-tp1473288p1473288.html Sent from the R help mailing list archive at Nabble.com.
try this t <- TazProperties.. v <- aggregate(t$Area, by=list(t$TAZ,t$Props), sum) names(v) <- c("TAZ", "Prop", "area") tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)]) note that you have to deal with the cases where there is a tie for the maximum. The above just returns the first maximum. Nikhil On Feb 8, 2010, at 1:14 PM, LCOG1 wrote:> > Good day all, > I am having an issue coercing my data. Below i have some data on > taxlots > and an associated TAZ(transportation analsysi zone) that each > property is > within. The main issue is that some properties cross TAZ boundaries > so i > need to make a decision as to which TAZ the property belongs too, i > would > like to do this based on the area of the Property and ultimately > assign the > the property to the TAZ in which the majority or the most of the > area is > within. For instance in the data below: > > Property p754921 is in two TAZs, 38 and 37. Since the property is > mostly > in 37 i would like to assign this value to the list of > properties(Props) so > that > > MultiTazProperties_ goes from > > $p754921 > [1] 38 37 37 > > $p75506 > [1] 171 171 282 171 > > $p75508 > [1] 46 46 169 169 169 > > to.... > > $p754921 > [1] 37 > > $p75506 > [1] 282 > > $p75508 > [1] 46 > > Props TAZ Area > 1 p754921 38 109828.040 > 2 p754921 37 128134.710 > 3 p754921 37 46469.570 > 4 p75506 171 37160.210 > 5 p75506 171 40080.500 > 6 p75506 282 344679.660 > 7 p75506 171 16972.280 > 8 p75508 46 342309.558 > 9 p75508 46 260906.870 > 10 p75508 169 17014.659 > 11 p75508 169 7285.706 > 12 p75508 169 10936.316 >> > > > #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) > > MultiTazProperties_<-tapply(TAZ , Props, function(x) x) > MultiTazArea_<-tapply(Area , Props, function(x) x) > > Hope my inquiry is clear. Thanks > -- > View this message in context: http://n4.nabble.com/Selecting-single-TAZ-based-on-area-proportion-tp1473288p1473288.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
It dopes appear that this code works but entering a NA into the TAZ values goofs things up. Any ideas of how to remedy this problem? -----Original Message----- From: Nikhil Kaza [mailto:nikhil.list at gmail.com] Sent: Monday, February 08, 2010 4:51 PM To: ROLL Josh F Cc: r-help at r-project.org Subject: Re: [R] Selecting single TAZ based on area proportion try this t <- TazProperties.. v <- aggregate(t$Area, by=list(t$TAZ,t$Props), sum) names(v) <- c("TAZ", "Prop", "area") tapply(v$area, v$Prop, function(x) v$TAZ[which.max(x)]) note that you have to deal with the cases where there is a tie for the maximum. The above just returns the first maximum. Nikhil On Feb 8, 2010, at 1:14 PM, LCOG1 wrote:> > Good day all, > I am having an issue coercing my data. Below i have some data on > taxlots and an associated TAZ(transportation analsysi zone) that each > property is within. The main issue is that some properties cross TAZ > boundaries so i need to make a decision as to which TAZ the property > belongs too, i would like to do this based on the area of the Property > and ultimately assign the the property to the TAZ in which the > majority or the most of the area is within. For instance in the data > below: > > Property p754921 is in two TAZs, 38 and 37. Since the property is > mostly in 37 i would like to assign this value to the list of > properties(Props) so > that > > MultiTazProperties_ goes from > > $p754921 > [1] 38 37 37 > > $p75506 > [1] 171 171 282 171 > > $p75508 > [1] 46 46 169 169 169 > > to.... > > $p754921 > [1] 37 > > $p75506 > [1] 282 > > $p75508 > [1] 46 > > Props TAZ Area > 1 p754921 38 109828.040 > 2 p754921 37 128134.710 > 3 p754921 37 46469.570 > 4 p75506 171 37160.210 > 5 p75506 171 40080.500 > 6 p75506 282 344679.660 > 7 p75506 171 16972.280 > 8 p75508 46 342309.558 > 9 p75508 46 260906.870 > 10 p75508 169 17014.659 > 11 p75508 169 7285.706 > 12 p75508 169 10936.316 >> > > > #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) > > MultiTazProperties_<-tapply(TAZ , Props, function(x) x) > MultiTazArea_<-tapply(Area , Props, function(x) x) > > Hope my inquiry is clear. Thanks > -- > View this message in context: > http://n4.nabble.com/Selecting-single-TAZ-based-on-area-proportion-tp1 > 473288p1473288.html Sent from the R help mailing list archive at > Nabble.com. > > ______________________________________________ > 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.