Using "if else" (and possibly other) conditionals inside \Sexpr{}
Is it possible to use conditionals inside \Sexper{} in Sweave? An example of what I'm trying to do is
\Sexpr{if(coef(model1)[3]<0){-1*round(coef(model1)[3],3)}else{round(coef(model1)[3],3)}}
More elaborately, I want something like
\Sexpr{if(x<0){paste(-1*x, "lower", sep="")}els开发者_开发百科e{paste(x, "higher", sep=""}}
When I try the first bit of code I get the following error:
Error in parse(text = cmd) : <text>:2:0: unexpected end of input
1:if(coef(model1)[3]<0){-1*round(coef(model1)[3],3)
Any ideas?
Thanks for your help,
-Mark
Curly brackets are not allowed in Sexpr
expressions. Instead do the computation in a hidden code chunk and use the result in an Sexpr
.
See the Sweave manual: https://stat.ethz.ch/R-manual/R-devel/library/utils/doc/Sweave.pdf
精彩评论