The following untested code might also be of some help to you:

x = data.frame(x = 1:5)
y = data.frame(y = 1:10)
z = data.frame(z = 1:3)
a = rnorm(50)
b = function(x) x^2

makeRowFrame <- function(){
    n <- ls(envir = .GlobalEnv)
    tempFunc <- function(VARIABLE){
        VARIABLEM <- get(VARIABLE)
        if(!is.data.frame(VARIABLEM)) return(invisible(NULL))
        VARIABLEM <- matrix(NROW(VARIABLEM))
        colnames(VARIABLEM) <- VARIABLE
        return(VARIABLEM)
    }
    return(unlist(sapply(n, tempFunc)))
}

It provides a function that searches your workspace for all data frames and
produces a new object with names of each of the available data frames and
the number of rows in each of them. It should skip things that aren't data
frames.

Let me know if it doesn't work and I'll debug it further.

Michael Weylandt

On Tue, Sep 20, 2011 at 2:28 PM, Sarah Goslee <sarah.gos...@gmail.com>wrote:

> Hi Kelly,
>
> c() creates a vector. You need data.frame() instead.
>
> dfIntron <- c(mC_Explant=nrow(mC_Explant), mC_Callus=nrow(mC_Callus),
> mC_RegenPlant=nrow(mC_RegenPlant)) # set colnames simultaneously.
>
> Sarah
>
> On Tue, Sep 20, 2011 at 2:23 PM, Vining, Kelly
> <kelly.vin...@oregonstate.edu> wrote:
> > Hello R users,
> > I have a set of data frames for which I am tallying row numbers, as shown
> below.
> >
> >> nrow(mC_Explant)
> > [1] 14480
> >> nrow(mC_Callus)
> > [1] 23320
> >> nrow(mC_RegenPlant)
> > [1] 8108
> >
> > etc.
> >
> > I want to create a new data frame which has the variable names as column
> headings, and then a single row with the nrow tallies. My first step was
> this:
> >
> > dfIntron <- c(nrow(mC_Explant), nrow(mC_Callus), nrow(mC_RegenPlant))
> >
> > Then, to set the column names, I tried this, and got the following error:
> >
> >  colnames(dfIntron) <- c("mC_Explant", "mC_Callus", "mC_RegenPlant")
> > Error in `colnames<-`(`*tmp*`, value = c("mC_Explant", "mC_Callus",
> "mC_RegenPlant" :
> >  attempt to set colnames on object with less than two dimensions
> >
> > Even my first step seems wildly inefficient, and obviously doesn't work.
> There must be a simple way to do this, but I can't use table(), for example,
> as there are multiple data frames.
> >
> > Any help will be appreciated.
> >
> > --Kelly V.
> >
> >
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> R-help@r-project.org 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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to