[R] normalizing prices to a specific year - how to?
dwinsemius at comcast.net
Thu Jan 27 22:03:34 CET 2011
On Jan 27, 2011, at 3:02 PM, Martin Hvidberg wrote:
> Dear list
> I have a large data frame with house prices. Prices have been
> to price per m2, to be able to compare. Prices are spread over
> almost 10
> years, each price is tagged with the year it relates to.
> I would like to 'normalize' all the prices to, eg. 2010 prices.
> The data frame looks like this
> Y P
> 1 2004 11199.60
> 2 2005 15310.10
> 3 2005 19491.50
> 4 2005 18656.70
> 5 2005 16092.00
> 6 2005 9929.08
> Y is Year and P is price (in Danish Kroner) per m2
> I looked in some old scripts and have written this:
> dafP$Yav <- ave(dafP$P,dafP$Y,FUN=mean) # Yav. Prices Weight per Year,
> i.e. Yearly mean
> dafP$Pno <- dafP$P * (mean(dafP$P)/dafP$Yav) # Prize Normalized by
> Can any one comment on this:
> This code only normalizes so all year get the same mean. How
> I go about 'normalizing' to a specific year, eg. 2010?
Maybe something like:
mn2010 <- head(dafP[which(dafP$Y==2010), "Yav"], 1) # get just first
with(dafP, tapply(P, Y, scale, center=mn2010) )
aggregate can be used with scale and may be better in some instances.
Testing is not done here because you failed to provide a useful example.
> Best Regards
> */ Martin Hvidberg
> Tanggårdsvej 22
> 2680 Solrød
> tlf.: 35 83 01 91
> email: Martin at Hvidberg.net /*
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help