Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer: continuousOps and updated fillna moved to OpasnetUtils)
(Answer: function timepoints moved from Building model)
Line 660: Line 660:
 
return(timeline)
 
return(timeline)
 
}
 
}
 +
 +
# Calculate the cumulative impact of the events on building stock to given years
 +
 +
timepoints <- function(X, obsyear) {
 +
# Function timepoints takes an event list and turns that into existing crosscutting situations at
 +
# timepoints defined by years.
 +
# X must be an ovariable with index Eventyear.
 +
# obsyear must be a vector of years.
 +
 +
if(is.factor(X@output$Eventyear))
 +
X@output$Eventyear <- as.numeric(levels(X@output$Eventyear)[X@output$Eventyear])
 +
# tapply (and therefore oapply) changes continuous indices to factors! Must change back by hand.
 +
 +
out <- data.frame()
 +
 +
for(i in obsyear) {
 +
out <- rbind(out, data.frame(
 +
Year = i,
 +
X@output[X@output$Eventyear <= i , ]
 +
))
 +
}
 +
X@output <- out
 +
X@marginal <- c(TRUE, X@marginal) # Add Year to marginal
 +
X <- oapply(X, cols = "Eventyear", FUN = "sum", na.rm = TRUE)
 +
X@output$Year <- as.numeric(levels(X@output$Year)[X@output$Year])
 +
X@output <- X@output[!is.na(result(X)) , ]
 +
return(X)
 +
}
 +
  
 
objects.store(ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, truncateIndex, findrest,  
 
objects.store(ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML, truncateIndex, findrest,  
unkeep, timing, makeTimeline)
+
unkeep, timing, makeTimeline, timepoints)
  
 
cat(paste("The following objects are stored: ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML,",
 
cat(paste("The following objects are stored: ograph, collapsemarg, MyPointKML, ova2spat, MyRmap, MyPlotKML,",
"truncateIndex, findrest, unkeep, timing, makeTimeline.\n"))
+
"truncateIndex, findrest, unkeep, timing, makeTimeline, timepoints.\n"))
 
</rcode>
 
</rcode>
  

Revision as of 13:55, 19 February 2014



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

Call the objects stored by this code from another rode with this command:

objects.latest("Op_en6007", code_name = "answer")

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>