[R] Printing contents of a variable

darnold dwarnold45 at suddenlink.net
Fri Aug 3 22:39:29 CEST 2012


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(c(0,1), n, replace=TRUE)
  y <- x
  y[y==0] <- "T"
  y[y==1] <- "H"
  p <- sum(x)/n
  p
}

Then run at the command line:

x <- CoinTosses(40)
x

The result is:

> x <- CoinTosses(40)
> x
[1] 0.475

Not sure why the former does not display the contents of x.

Thanks.

D.



--
View this message in context: http://r.789695.n4.nabble.com/Printing-contents-of-a-variable-tp4639106.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list