my.datafile <- tempfile() cat(file=my.datafile, " 1 0 0 6 32 12 1 0 2 0 0 2 22 21 5 1 3 0 0 7 26 17 1 0 4 0 4 25 16 6 0 0 5 0 0 4 34 12 1 0 6 0 6 32 12 1 0 0 7 0 0 16 21 13 1 0 8 0 0 0 18 29 3 1 9 0 0 7 35 8 1 0 10 0 0 6 28 14 3 0 11 0 0 3 33 14 1 0 12 0 5 38 6 2 0 0 13 0 0 3 26 18 4 0 14 0 0 14 24 10 3 0 15 0 0 0 20 25 4 2 16 0 18 30 2 1 0 0 17 0 0 1 31 18 1 0 18 0 0 5 33 12 1 0 ", sep=" ") golfdat <- read.table(my.datafile, header=FALSE, col.names=c("hole", "count.1s", "count.2s", "count.3s", "count.4s", "count.5s", "count.6s", "count.7s")) scores <- NULL for (i in 1:18){ scores <- c(scores,rep(1:7, times=golfdat[i,-1])) } hole.number <- rep(1:18,each=51) scores.hole1 <- scores[hole.number==1] scores.hole2 <- scores[hole.number==2] ## ## continue with similar code (or use R loop)... ## scores.hole18 <- scores[hole.number==18]