[R] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'

David Winsemius dwinsemius at comcast.net
Thu Dec 2 11:36:42 CET 2010


On Dec 2, 2010, at 5:22 AM, Karl Brand wrote:

> 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...
>

This reminds me of physicists using high energy particles to  
investigate the structure of the nucleus. But you have alternatives to  
what might be called "destructive debugging through binoculars".  
Instead of throwing code at your data and asking the assembled  
audience of soothsayers to tell you what went wrong by examining the  
debris, why don't you show us what the data objects actually look like?

-- 
David.

> 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-bounces at r-project.org
>>> [mailto:r-help-bounces at r-project.org] On Behalf Of Karl Brand
>>> Sent: Wednesday, December 01, 2010 6:35 AM
>>> To: Dimitris Rizopoulos
>>> Cc: r-help at 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.brand at 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 at 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.brand at 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 at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list