firstOc <- function(x) { n <- length(x) index <- c(1:n) first <- min(index[x=="K"], Inf) return(first) } versuche <- 10000 m <- 100 n <- versuche*m x <- matrix(sample(c("K","Z"), n, replace=TRUE), nrow=versuche, ncol=m) fir <- apply(x, 1, firstOc) count <- vector(mode="integer", length=m) names(count) <- c(1:m) for( a in 1:m ) { count[a] <- length(fir[fir==a]) } barplot(count/sum(count), axis.lty=2, space=0, xlab="Anzahl Würfe bis Kopf", main=paste("Versuche = ", versuche, " m = ", m), col="orange2", xlim=c(0,20))