s-news
[Top] [All Lists]

Assignment within a function

To: S-News <s-news@wubios.wustl.edu>
Subject: Assignment within a function
From: Kim Elmore <Kim.Elmore@noaa.gov>
Date: Tue, 11 Nov 2008 16:25:51 -0600
User-agent: Thunderbird 2.0.0.17 (Windows/20080914)
I need to calculate he silhouette coefficient for a cluster object after passing it through cutree(), which essentially returns a vector. I've written a function to do this, to which I pass a distance object (such as results from daisy() or dist()) and the output from cutree(). All works normally as a script, but when I make it into a function, called silcoeff.fun(), I keep getting the following error:

Problem in silcoeff.fun(euclidean.no55.dis, cluster..: object "a" must be assigned locally before replacement
Use traceback() to see the call stack

When I look at traceback(), I see:

5: eval(action, sys.parent())
4: doErrorAction("Problem in silcoeff.fun(euclidean.no55.dis, cluster..: object \"a\" must be assigned locally before replacement",
3: silcoeff.fun(euclidean.no55.dis, clusters.samp)
2: eval(expression(silcoeff.fun(euclidean.no55.dis, clusters.samp)))
1:
Message: Problem in silcoeff.fun(euclidean.no55.dis, cluster..: object "a" must be assigned locally before replacement

I'm not sure what object "a" is nor do I understand why I get this. I've tried passing the distance object to the function as a matrix (I otherwise convert it to a matrix internally), and I've tried passing the results of cutree to the function as a regular vector all to no avail. If I hard wire the dissimilarity and cutree input internally into the function, all is well, but when I try to pass these in, I get this error.

Would someone please clue me into what I'm doing wrong?

Kim Elmore

--
Kim Elmore, Ph.D. (PP SEL/MEL/Glider, N5OP, 2nd Class Radiotelegraph, GROL)
"All weather is divided into three parts: Yes, No and Maybe. The greatest of these 
is maybe." -- The original Latin appears to be garbled.


<Prev in Thread] Current Thread [Next in Thread>