I didn't change your "rownames" to "row.names"
because I figured you had the name you wanted
but only forgot to include the quotes.  Both "rownames"
and "row.names" are valid inputs, but they mean
different things.  Howver, without the quotes you were
passing in the contents of the object called
rownames, which happens to be a function (aka a closure),
not the string "rownames.  The quotes are needed to
distinguish between things and names of things.
Some functions (e.g., library() and help()) try
to cover up this difference, leading to occasional
difficulties using them.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -----Original Message-----
> From: Karl Brand [mailto:k.br...@erasmusmc.nl] 
> Sent: Thursday, December 02, 2010 2:22 AM
> To: William Dunlap
> Cc: r-help@r-project.org; Dimitris Rizopoulos
> Subject: Re: [R] attempted merge() returns: cannot coerce 
> type 'closure' to vector of type 'any'
> 
> Cheers Bill.
> 
> You got me halfway, since:
> 
>  > temp <- merge(x=x, y=y[,17, drop=FALSE], by="rownames", sort=FALSE)
> Error in fix.by(by.x, x) : 'by' must specify valid column(s)
> 
> but, using "row.names" instead of "rownames", like:
>  > temp <- merge(x=x, y=y[,17, drop=FALSE], by="row.names", 
> sort=FALSE)
> 
> works (but adds a column "Row.names").
> 
> Which seems some what counter intuitive to me since i am 
> feeding in two 
> matrices to the merge function, which i understand have 
> 'rownames', not 
> 'row.names' as data frames have, right? Although the output 
> of merge() 
> is a data frame...
> 
> thanks again,
> 
> Karl
> 
> 
> On 12/1/2010 6:08 PM, William Dunlap wrote:
> > Try
> >     by="rownames"
> > instead of
> >     by=rownames
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >> -----Original Message-----
> >> From: r-help-boun...@r-project.org
> >> [mailto:r-help-boun...@r-project.org] On Behalf Of Karl Brand
> >> Sent: Wednesday, December 01, 2010 6:35 AM
> >> To: Dimitris Rizopoulos
> >> Cc: r-help@r-project.org
> >> Subject: [R] attempted merge() returns: cannot coerce type
> >> 'closure' to vector of type 'any'
> >>
> >> Hi Dimtris and esteemed useRs,
> >>
> >> I don't understand why i get this error message when
> >> attempting to use
> >> merge() -
> >>
> >>   >  temp<- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE)
> >> Error in as.vector(x, mode) :
> >>     cannot coerce type 'closure' to vector of type 'any'
> >>
> >> It should work because:
> >>
> >>   >  all(rownames(x[order(rownames(x)),]) ==
> >> + rownames(y[order(rownames(y[,17, drop=FALSE])),17,
> >> drop=FALSE]) ....
> >> [TRUNCATED]
> >> [1] TRUE
> >>
> >> also:
> >>
> >>   >  class(x); class(y[,17, drop=FALSE])
> >> [1] "matrix"
> >> [1] "matrix"
> >>
> >>
> >> Any idea why i cant use merge() in the normal way here? 
> I'm forced to
> >> add the column using:
> >>
> >> temp.b<- cbind(x, y[match(rownames(x), rownames(y)),17])
> >>
> >> All insights appreciated for this leaRner,
> >>
> >> cheers,
> >>
> >> Karl
> >>
> >>
> >> --
> >> Karl Brand<k.br...@erasmusmc.nl>
> >> Department of Genetics
> >> Erasmus MC
> >> Dr Molewaterplein 50
> >> 3015 GE Rotterdam
> >> P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268
> >>
> >> ______________________________________________
> >> 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.
> >>
> 
> -- 
> Karl Brand <k.br...@erasmusmc.nl>
> Department of Genetics
> Erasmus MC
> Dr Molewaterplein 50
> 3015 GE Rotterdam
> P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268
> 

______________________________________________
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