I assume that you need to download the data access package.
So you need to add at the beginning of the loop:
require(dat.list[[i, "Package"]], character.only = TRUE)
(see this question why you need to use the charachter.only variable)
Note that you also need to change your loop:
for(i in nrow(dat.list))
to
for(i in 1:nrow(dat.list))
There is another problem: some data arrays are returned with a name also in parentheses. For example:
wine.classes (wine)
So we need to take them off. Easy to do with:
dat.list[,3] <- sapply(strsplit(dat.list[,3], " "), function(x){x[1]})
Finally, dat.list can only be obtained using [] , you do not need [[]] (easier to read!).
So finally:
# List of all installed packages dat.list <- data(package=.packages(all.available=TRUE))$results # Remove package name in parentheses dat.list[,3] <- sapply(strsplit(dat.list[, "Item"], " "), function(x){x[1]}) idx <- c() for (i in 1:nrow(dat.list)) { require(dat.list[i, "Package"], character.only = T) nme <- dat.list[i,"Item"] # data set as string data(list=nme, package=dat.list[i,"Package"]) # load the data dat <- eval(as.name(nme)) # assign the data to the variable dat ncl <- ncol(dat) if(!is.null(ncl) && ncl >= 6) idx <- c(idx, i) }
and
> dat.list[idx, "Item"] [1] "Seatbelts" "USJudgeRatings" "WorldPhones" "airquality" [5] "anscombe" "attitude" "crimtab" "euro.cross" [9] "infert" "longley" "mtcars" "occupationalStatus" [13] "state.x77" "swiss" "volcano" "car.test.frame" [17] "car90" "solder" "stagec" "bladder" [21] "bladder1" "bladder2" "cancer" "cgd" [25] "cgd0" "colon" "flchain" "heart" [29] "jasa" "jasa1" "kidney" "lung" [33] "mgus" "mgus1" "mgus2" "nwtco" [37] "ovarian" "pbc" "pbcseq" "rats2" [41] "transplant" "veteran" "soldat" "patch" [45] "tooth"