Skip to content

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

7 messages · David Winsemius, Karl Brand, William Dunlap

#
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:

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

            
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?
#
On 12/2/2010 11:36 AM, David Winsemius wrote:
Ofcourse David, sorry- my lazy.

Is str() enough to put away the binoculuars and maybe highlight the 
source of my ignorance?

 > str(x)
  num [1:140, 1:7] 4.93e-02 2.83e-02 1.07e-02 2.68e-02 3.92e-05 ...
  - attr(*, "dimnames")=List of 2
   ..$ : chr [1:140] "1415743_at" "1415887_at" "1416332_at" 
"1416340_a_at" ...
   ..$ : chr [1:7] "R.S.adj.pvalue" "R.S.Tau" "R.S.xpiek" "R.S.xdal" ...

 > str(y)
  num [1:140, 1:18] 0.573 1 0.752 0.768 0.399 ...
  - attr(*, "dimnames")=List of 2
   ..$ : chr [1:140] "1427982_s_at" "1430520_at" "1454086_a_at" 
"1419652_s_at" ...
   ..$ : chr [1:18] "R.S.1" "R.S.2" "R.S.3" "R.S.4" ...
 > source(.trPaths[5], echo=TRUE, max.deparse.length=150)

 > str(temp)
'data.frame':   140 obs. of  9 variables:
  $ Row.names     :Class 'AsIs'  chr [1:140] "1415743_at" "1415887_at" 
"1416332_at" "1416340_a_at" ...
  $ R.S.adj.pvalue: num  4.93e-02 2.83e-02 1.07e-02 2.68e-02 3.92e-05 ...
  $ R.S.Tau       : num  21.6 23.6 26.6 29.7 18.8 20 24.6 27.9 23.9 22.7 ...
  $ R.S.xpiek     : num  6.74 17.46 15.81 15.39 14.73 ...
  $ R.S.xdal      : num  16.94 1.76 22.8 1.12 5.41 ...
  $ R.S.p1        : num  0.0004 0.0001 0.0467 0.0024 0 ...
  $ R.S.p2        : num  0.0039 0 0.002 0.019 0.0001 0.0035 0.0351 
0.0126 0.0028 0.0192 ...
  $ R.S.p3        : num  0.0178 0.0004 0.0101 0.0312 0.0012 0.022 0.0008 
0.0151 0.0048 0.0317 ...
  $ V1            : num  3.96 -0.94 1.04 1.94 -2.53 ...
 >
#
On Dec 2, 2010, at 5:58 AM, Karl Brand wrote:
Inserting earlier debris:
At this point I think Bill should have suggested by="row.names" since  
that is the correct argument to merge() when asking for a rownames  
match, and you appear to have found that by experimentation since you  
didn't seem to have read the help page.
OK. It added a column what's the problem? The help(merge) pages says:
"If the matching involved row names, an extra character column called  
Row.names is added at the left, and in all cases the result has  
?automatic? row names."
Right. The merge function takes either dataframes or things which can  
be coerced to dataframes as arguments and returns a dataframe. That is  
exactly what the help(merge) page states outright (in many places).  
Just because your arguments were matrices doesn't mean the returned  
object should be one. Had you wanted it to be an "augmented"  
data.matrix with rownames as before, you could gotten that after merge  
by:

?data.matrix
temp2 <- datamatrix(temp[-1])
rownames(temp2) <- temp$Row.names

(Or by the rather nice manipulations that you described using rownames  
as indices.)

I think I understand the "problem" now .... that you were expecting  
merge() to behave differently than is documented.
#
On 12/2/2010 3:52 PM, David Winsemius wrote:
Cheers David,

You nailed it- closer attention to the help page would defiently have 
saved us time.

No less, thanks a lot for highlighting this, and also for the merge() 
clarifications.

And insight into what physicists have to deaal with :)

cheers,

Karl
#
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
#
Cheers Bill,

Thank you for the clarificaiton. Prabably showing the str() of these 
objects would have made it easier for you see exatly where i was going 
wrong. Which as David pointed out, was really a lack of ?merge reading...:)

Karl
On 12/2/2010 5:46 PM, William Dunlap wrote: