Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all<-ls() for (f in all) print(dim(f)) -- Farrel Buchinsky [[alternative HTML version deleted]]
You need something like this: sapply(objects() , function(x)(dim(eval(parse(text = x))))) a <- rnorm(1) b <- matrix(rnorm(4), ncol = 2, nrow = 2) sapply(objects() , function(x)(dim(eval(parse(text = x))))) $a NULL $b [1] 2 2 Cheers, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -----Oorspronkelijk bericht----- Van: r-help-bounces op stat.math.ethz.ch [mailto:r-help-bounces op stat.math.ethz.ch] Namens Farrel Buchinsky Verzonden: dinsdag 9 januari 2007 15:30 Aan: r-help op stat.math.ethz.ch Onderwerp: [R] dimensions of a all objects Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all<-ls() for (f in all) print(dim(f)) -- Farrel Buchinsky [[alternative HTML version deleted]] ______________________________________________ R-help op stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Farrel Buchinsky wrote:> Why will the following command not work > sapply(objects(),dim) > What does it say about the objects list? What does it say about the dim > command? > > Likewise, the following also does not work > all<-ls() > for (f in all) print(dim(f))'objects()' returns character strings - the names of objects - then the dim of the character strings are all NULL. I'll assume that's what you are getting at - you've not posted an example or the output you are getting or why it 'does not work'. Maybe you want this: > sapply(objects(),function(x){dim(get(x))}) $f NULL $m [1] 2 5 $x NULL $y [1] 5 2 - where m and y are matrices, f is a function, x is a scalar. Barry
Generally it is difficult to get an overview of what's there. But the following function I acquired from (???) ages ago does a nice job: lls <- function (pos = 1, pat = "") { dimx <- function(dd) if (is.null(dim(dd))) length(dd) else dim(dd) lll <- ls(pos = pos, pat = pat) cat(formatC("mode", 1, 15), formatC("class", 1, 18), formatC("name", 1, max(nchar(lll)) + 1), " size\n-------------------------------------------------------\n") if (length(lll) > 0) { for (i in 1:length(lll)) { cat(formatC(eval(parse(t = paste("mode(", lll[i], ")"))), 1, 15), formatC(paste(eval(parse(t paste("class(", lll[i], ")"))), collapse = " "), 1, 18), formatC(lll[i], 1, max(nchar(lll)) + 1), " ", eval(parse(t paste("dimx(", lll[i], ")"))), "\n") } } } Just say lls() and you get a reasnoable listing of obejcts. Best, Bendix ______________________________________________ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) bxc at steno.dk http://www.biostat.ku.dk/~bxc ______________________________________________> -----Original Message----- > From: Farrel Buchinsky [mailto:fjbuch at gmail.com] > Sent: Tuesday, January 09, 2007 3:30 PM > To: r-help at stat.math.ethz.ch > Subject: [R] dimensions of a all objects > > Why will the following command not work > sapply(objects(),dim) > What does it say about the objects list? What does it say > about the dim command? > > Likewise, the following also does not work > all<-ls() > for (f in all) print(dim(f)) > -- > Farrel Buchinsky > > [[alternative HTML version deleted]] > > >