OpasnetUtils/Summary.bring: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(Created page with "Category:Opasnet Category:R tools {{method|moderator=|stub=Yes}} ==Description== Bring parts of summary table. ==Parameters== * page is the page identifier for the summ...")
 
(code replaced with link to code)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Opasnet]]
[[Category:Opasnet]]
[[Category:R tools]]
[[Category:R tools]]
[[Category:OpasnetUtils]]
{{method|moderator=|stub=Yes}}
{{method|moderator=|stub=Yes}}


Line 10: Line 11:


==Code==
==Code==
<rcode
name="answer"
label="Initiate functions"
graphics="1"
>
# SUMMARY.BRING ############## summary.bring: Bring parts of summary table
#  page is the page identifier for the summary table.
summary.bring <- function(page, base = "opasnet_base"){
data <- tidy(op_baseGetData(base, page))
pages <- levels(data$Page)


## temp contains the additional information that is not on the actual data table.
https://www.opasnet.org/svn/opasnet_utils/trunk/R/SummaryBring.r
temp <- data[, !colnames(data) == "Observation"]
temp <- reshape(temp, idvar = "Page", timevar = "Index", direction = "wide")
colnames(temp) <- ifelse(substr(colnames(temp), 1, 7) == "Result.", substr(colnames(temp), 8, 50), colnames(temp))
 
## Get all data tables one at a time and combine them.
for(i in 1:length(pages)){
out <- op_baseGetData("opasnet_base", pages[i])
out <- tidy(out)
cols <- colnames(out)[!colnames(out) %in% c("Observation", "Result")]
out <- reshape(out, timevar = "Observation", idvar = cols, direction = "wide")
colnames(out) <- ifelse(substr(colnames(out), 1, 7) == "Result.", substr(colnames(out), 8, 50), colnames(out))
out <- merge(temp[temp$Page == pages[i], ][colnames(temp) != "Page"], out)
 
## Check that all data tables have all the same columns before you combine them with rbind.
if(i == 1){out2 <- out} else {
addcol <- colnames(out2)[!colnames(out2) %in% colnames(out)]
if(length(addcol) > 0) {
temp <- as.data.frame(array("*", dim = c(1,length(addcol))))
colnames(temp) <- addcol
out <- merge(out, temp)}
addcol <- colnames(out)[!colnames(out) %in% colnames(out2)]
if(length(addcol) > 0) {
temp <- as.data.frame(array("*", dim = c(1,length(addcol))))
colnames(temp) <- addcol
out2 <- merge(out2, temp)}
 
## Combine data tables.
out2 <- rbind(out2, out)}
}
return(out2)
}
</rcode>


==See also==
==See also==

Latest revision as of 14:01, 16 August 2012



Description

Bring parts of summary table.

Parameters

  • page is the page identifier for the summary table.

Code

https://www.opasnet.org/svn/opasnet_utils/trunk/R/SummaryBring.r

See also