[R] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
wdunlap at tibco.com
Thu Dec 2 17:46:37 CET 2010
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.
Spotfire, TIBCO Software
> -----Original Message-----
> From: Karl Brand [mailto:k.brand at erasmusmc.nl]
> Sent: Thursday, December 02, 2010 2:22 AM
> To: William Dunlap
> Cc: r-help at 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",
> 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,
> 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]
> >>  TRUE
> >> also:
> >> > class(x); class(y[,17, drop=FALSE])
> >>  "matrix"
> >>  "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
More information about the R-help