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
converted
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
head(dafP)
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
Year
Can any one comment on this:
*
This code only normalizes so all year get the same mean. How
would
I go about 'normalizing' to a specific year, eg. 2010?
? tapply
Maybe something like:
mn2010 <- head(dafP[which(dafP$Y==2010), "Yav"], 1) # get just first
2010 value
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.
--
David
Best Regards
Martin
--
*/ Martin Hvidberg
Tanggårdsvej 22
2680 Solrød
tlf.: 35 83 01 91
email: mar...@hvidberg.net /*
[[alternative HTML version deleted]]
______________________________________________
R-help@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.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@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.