Displaying 2 results from an estimated 2 matches for "cointosses".
2012 Aug 03
1
Printing contents of a variable
All,
Can someone explain why this does not print the contents of x when I source
this file?
CoinTosses <- function(n,print=TRUE) {
x <- sample(c(0,1), n, replace=TRUE)
y <- x
y[y==0] <- "T"
y[y==1] <- "H"
p <- sum(x)/n
p
}
x <- CoinTosses(40)
x
On the other hand, if I source this file:
CoinTosses <- function(n,print=TRUE) {
x <- sample(...
2012 Aug 03
2
Printing a summary
All,
Is this typical of how people will print a summary of results?
CoinTosses <- function(n) {
x <- sample(c(0,1), n, replace=TRUE)
y <- x
y[y==0] <- "T"
y[y==1] <- "H"
numHeads <- sum(x)
numTails <- n-sum(x)
p <- numHeads/n
cat(cat(y,sep=""),"\n")
cat("Number of heads: ", numHeads, &...