Mori/Codetest: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
(Progress?)
Line 1: Line 1:
===Old R-code===
===Old R-code===
'''Test code


<rcode>
<rcode>
library(xtable)
library(xtable)
library(OpasnetUtils)
library(OpasnetUtils)
var1 <- data.frame(c = c("A", "A", "C"), d = c("D", "E", "E"), Result = 4:6)
var1 <- data.frame(c = c("A", "A", "C"), d = c("D", "E", "E"), Result = 4:6)
var2 <- var1
cat("var1\n")
dec <- data.frame(Decision = rep(c("Decision 1", "Decision 2"), each = 2), Option = c("OptA", "OptB"), Variable = c("var1", "var1", "var1", "var2"), Cell = c(" c: A; d: E", " d: D"), Change = c("Replace", "Multiply"), Result = 7:10)
print(xtable(var1), type = "html")
var1
 
dec
var2 <- data.frame(c = c("A", "A", "C"), d = c("D", "E", "E"), Result = 4:6)
cat("var2\n")
print(xtable(var2), type = "html")
 
dec <- data.frame(
                  Decision = rep(c("Decision 1", "Decision 2"), each = 2),  
                  Option = c("OptA", "OptB"),  
                  Variable = c("var1", "var1", "var1", "var2"),  
                  Cell = c(" c: A; d: E", " d: D"),  
                  Change = c("Replace", "Multiply"),  
                  Result = 7:10)
 
cat("Decision\n")
print(xtable(dec), type = "html")
 
out <- decisions.apply(dec)
out <- decisions.apply(dec)
cat("Variable", names(out)[1], "\n")
 
cat("Variable", names(out)[1], "output\n")
print(xtable(out[[1]]), type = 'html')
print(xtable(out[[1]]), type = 'html')
cat("Variable", names(out)[2], "\n")
 
cat("Variable", names(out)[2], "output\n")
print(xtable(out[[2]]), type = 'html')
print(xtable(out[[2]]), type = 'html')
data <- tidy(op_baseGetData("opasnet_base", "Op_en5466"), direction = "wide")
data <- data[colnames(data) != "Unit"]
data
data <- decisions.apply(data)


</rcode>
</rcode>
Line 26: Line 36:
{{attack|# |Why does the var2 outcome show row 3 OptB A E 50, because the decision should be applied only for row 1 OptB A D 4 ? There is a bug somewhere. |--[[User:Jouni|Jouni]] 16:12, 16 May 2012 (EEST)}}
{{attack|# |Why does the var2 outcome show row 3 OptB A E 50, because the decision should be applied only for row 1 OptB A D 4 ? There is a bug somewhere. |--[[User:Jouni|Jouni]] 16:12, 16 May 2012 (EEST)}}


===="Selvemmät" printit====
 
===Test Code===


{{comment|# |Oletko saanut bugin selville? Luulen, että decisions.apply jossain vaiheessa sekoittaa rivit niin, että ensimmäiselle riville tarkoitettu kertolasku kohdistuukin kolmannelle riville. Mutta miksi?|--[[User:Jouni|Jouni]] 08:53, 29 June 2012 (EEST)}}
{{comment|# |Oletko saanut bugin selville? Luulen, että decisions.apply jossain vaiheessa sekoittaa rivit niin, että ensimmäiselle riville tarkoitettu kertolasku kohdistuukin kolmannelle riville. Mutta miksi?|--[[User:Jouni|Jouni]] 08:53, 29 June 2012 (EEST)}}
Line 46: Line 57:
                   Decision = rep(c("Decision 1", "Decision 2"), each = 2),  
                   Decision = rep(c("Decision 1", "Decision 2"), each = 2),  
                   Option = c("OptA", "OptB"),  
                   Option = c("OptA", "OptB"),  
                   Variable = c("var1", "var1", "var1", "var2"),  
                   Variable = c("var2", "var1", "var1", "var2"),  
                   Cell = c(" c: A; d: E", " d: D"),  
                   Cell = c(" c: A; d: E", " d: D"),  
                   Change = c("Replace", "Multiply"),  
                   Change = c("Replace", "Multiply"),  
Line 82: Line 93:
var <- merge(scenarios[colnames(scenarios) != "temp"], var)
var <- merge(scenarios[colnames(scenarios) != "temp"], var)


print(xtable(dec.var), type = 'html')
#print(xtable(dec.var), type = 'html')
print(xtable(var), type = 'html')
#print(xtable(var), type = 'html')


for(s in 1:nrow(dec.var)) {cat(s)}
for(s in 1:nrow(dec.var)) {cat(s)}
Line 117: Line 128:


</rcode>
</rcode>
===New R-code===

Revision as of 10:36, 9 July 2012

Old R-code

+ Show code

⇤--#: . Why does the var2 outcome show row 3 OptB A E 50, because the decision should be applied only for row 1 OptB A D 4 ? There is a bug somewhere. --Jouni 16:12, 16 May 2012 (EEST) (type: truth; paradigms: science: attack)


Test Code

----#: . Oletko saanut bugin selville? Luulen, että decisions.apply jossain vaiheessa sekoittaa rivit niin, että ensimmäiselle riville tarkoitettu kertolasku kohdistuukin kolmannelle riville. Mutta miksi? --Jouni 08:53, 29 June 2012 (EEST) (type: truth; paradigms: science: comment)

----#: . Itsekin ajattelin samaa, mutta en ole vielä ymmärtänyt miksi se toimii niin.. Minulla meni pari päivää jahdatessa tuon yhden virheilmoituksen syytä, kunnes Teemu selvensi minulle että se on tarkoituskin tulla, joskin virheilmoituksessa on kuulemma parantamisen varaa. Nyt vasta alan ymmärtää paremmin miten tuo decisions.apply oikein toimii. --Mori 17:06, 3 July 2012 (EEST) (type: truth; paradigms: science: comment)

+ Show code