Difference between revisions of "Power.R"
m (typos) |
m |
||
(21 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | vnames <- c("Date","Reading","Estimate"," | + | # {{R}} |
− | + | vnames <- c("Date","Reading","Estimate","DailyConsumption","cents per Kwh","Dollars") | |
− | + | csv <- scan(sep=",", what="") | |
12/24/04,30987,0,0,0,0 | 12/24/04,30987,0,0,0,0 | ||
01/19/05,31294,0,11.8,14.07,65.99 | 01/19/05,31294,0,11.8,14.07,65.99 | ||
Line 24: | Line 24: | ||
09/28/06,52471,0,273.57,14.78,1284.17 | 09/28/06,52471,0,273.57,14.78,1284.17 | ||
10/10/06,53080,0,50.75,14.78,"NA" | 10/10/06,53080,0,50.75,14.78,"NA" | ||
+ | 10/12/06, 53162,0,41,14.78, "NA" | ||
+ | 10/28/06, 53710, 0, 28.25, 14.78, "NA" | ||
+ | 11/11/06, 54263, 0, 39.5, 14.78, "NA" | ||
"" | "" | ||
− | dim( | + | dim(csv) <- c(6,25) |
− | dset <- t( | + | dset <- t(csv) |
− | dset <- data.frame(dset) | + | dset <- as.data.frame(dset) |
names(dset) <- vnames | names(dset) <- vnames | ||
− | + | dset$"DailyConsumption" <- as.numeric(levels(dset$"DailyConsumption"))[unclass(dset$"DailyConsumption")] | |
+ | dset$Estimate <- as.numeric(levels(dset$Estimate))[unclass(dset$Estimate)] | ||
+ | dset$Date <- dates(levels(dset$Date)[unclass(dset$Date)]) | ||
+ | dset$TrueDaily <- diff(as.numeric(as.character(x))) / diff(dset$Date) | ||
dset | dset | ||
− | |||
− | |||
library(chron) | library(chron) | ||
− | |||
− | |||
− | |||
− | + | # Estimated monthly usage between May and September | |
− | + | mean(dset[18:21,4]) | |
# Estimated monthly usage between May and September | # Estimated monthly usage between May and September | ||
− | mean(dset[ | + | dset$GroupReads <- c(0,cumsum(abs(dset$Estimate-1))[-22])+1 |
+ | smoothedDailyLevels <- as.vector(tapply(dset$"DailyConsumption"[-22],dset$GroupReads, mean))[-1] | ||
+ | dset$smoothedDaily <- smoothedDailyLevels[dset$GroupReads] | ||
+ | dset | ||
+ | |||
+ | plot(DailyConsumption~Date, data=dset) | ||
+ | points(dset$Date[dset$Estimate==0], dset$"DailyConsumption"[dset$Estimate==0], col="blue", pch=16, cex=1) | ||
+ | lines(dset$Date, dset$smoothedDaily, col="red", lty=2) |
Latest revision as of 00:44, 6 June 2007
Code snipits and programs written in R, S or S-PLUS vnames <- c("Date","Reading","Estimate","DailyConsumption","cents per Kwh","Dollars") csv <- scan(sep=",", what="") 12/24/04,30987,0,0,0,0 01/19/05,31294,0,11.8,14.07,65.99 02/15/05,31910,1,22,14.07,116.26 03/15/05,32121,0,7.5,14.07,52.15 05/16/05,33114,0,17.9,14.07,113.79 06/15/05,33564,1,15,14.53,93.98 07/15/05,34765,0,40,14.53,216.7 08/16/05,35245,1,15,14.53,100.23 09/15/05,37356,0,70.4,14.53,365.44 10/17/05,37836,1,15,14.53,100.25 11/15/05,38957,0,38.7,14.53,211.28 12/16/05,39422,1,15,15.7,104.67 01/17/06,40115,0,21.7,15.7,145.69 02/14/06,40535,1,15,15.7,94.55 03/15/06,41148,0,21.1,15.7,129.33 04/12/06,41568,1,15,16.4,96.15 05/15/06,43284,0,52,16.4,341.09 06/15/06,44121,1,27,16.4,177.46 06/29/06,44241,1,9.23,14.78,24.83 08/31/06,44811,1,9.05,14.78,118.41 09/28/06,52471,0,273.57,14.78,1284.17 10/10/06,53080,0,50.75,14.78,"NA" 10/12/06, 53162,0,41,14.78, "NA" 10/28/06, 53710, 0, 28.25, 14.78, "NA" 11/11/06, 54263, 0, 39.5, 14.78, "NA" ""
dim(csv) <- c(6,25) dset <- t(csv)
dset <- as.data.frame(dset) names(dset) <- vnames dset$"DailyConsumption" <- as.numeric(levels(dset$"DailyConsumption"))[unclass(dset$"DailyConsumption")] dset$Estimate <- as.numeric(levels(dset$Estimate))[unclass(dset$Estimate)] dset$Date <- dates(levels(dset$Date)[unclass(dset$Date)]) dset$TrueDaily <- diff(as.numeric(as.character(x))) / diff(dset$Date) dset
library(chron)
- Estimated monthly usage between May and September
mean(dset[18:21,4])
- Estimated monthly usage between May and September
dset$GroupReads <- c(0,cumsum(abs(dset$Estimate-1))[-22])+1 smoothedDailyLevels <- as.vector(tapply(dset$"DailyConsumption"[-22],dset$GroupReads, mean))[-1] dset$smoothedDaily <- smoothedDailyLevels[dset$GroupReads] dset
plot(DailyConsumption~Date, data=dset) points(dset$Date[dset$Estimate==0], dset$"DailyConsumption"[dset$Estimate==0], col="blue", pch=16, cex=1) lines(dset$Date, dset$smoothedDaily, col="red", lty=2)