[R] How to transfer variable names to column names?
sarah.goslee at gmail.com
Tue Sep 20 20:28:11 CEST 2011
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.
On Tue, Sep 20, 2011 at 2:23 PM, Vining, Kelly
<Kelly.Vining at oregonstate.edu> wrote:
> Hello R users,
> I have a set of data frames for which I am tallying row numbers, as shown below.
>  14480
>  23320
>  8108
> 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.
More information about the R-help