Reputation: 203
When I run the following line by line in R it works fine, but with knitr
the options(digits=3)
gets ignored.
Why? Any solutions?
<<cor>>=
#mock up data set.
x <- c(rnorm(100))
y <- c(rnorm(100))
z <- c(rnorm(100))
df <- as.data.frame(cbind(x,y,z))
df$x<- as.numeric(df$x)
df$y<- as.numeric(df$y)
df$z<- as.numeric(df$z)
options(digits=3)
cor(df, use = 'na.or.complete', method = c("spearman"))
@
Upvotes: 4
Views: 1667
Reputation: 203
I found a solution while searching for a different issue. Leave out options(digits=3)
and use
round(cor(df, use = "na.or.complete", method = c("spearman")), digits = 3)
Which leaves the question why the options(...)
doesn't work. But I can happily live with that!
Thanks everyone for their time!
Gerit
Upvotes: 1