That may just be a vector with two elements, so functions designed for  
matrices are not going to "work". Why are you taking means of such  
small data objects anyway?

 > obj <- c(x=640, y=410)
 > obj
   x   y
640 410
 > str(obj)
  Named num [1:2] 640 410
  - attr(*, "names")= chr [1:2] "x" "y"
 > mean(obj)
[1] 525


On Aug 3, 2009, at 10:18 AM, Paulo Eduardo Cardoso wrote:

> Both objects are numeric, but they differ in structure and I don't  
> know how to handle both with a single function to get means.
>
> When I try to apply colMeans to a named numeric object like this:
>> Named num [1:2] 670 314
>>  - attr(*, "names")= chr [1:2] "x" "y"
>
> I get the error messages:
>
> Error in colMeans(centroid) :
>   'x' must be an array of at least two dimensions
>
> and apply(object,2,mean)
>
> Error in apply(object, 2, mean) : dim(X) must have a positive length
>
> There are something very basic that I'm missing.
>
> 2009/8/3 David Winsemius <dwinsemius@comcast.net>
>
> On Aug 3, 2009, at 9:52 AM, Paulo Eduardo Cardoso wrote:
>
>> Thanks. Works
>>
>> A doubt.
>>
>> I asked that because I have a loop that can generate objects like  
>> that or this one
>>
>>
>> str(object)
>> Named num [1:2] 670 314
>>  - attr(*, "names")= chr [1:2] "x" "y"
>>
>> To avoid using a ifelse() to calculate means of x and y, I'd like a  
>> function that handle with this named numeric object and that list.  
>> Any chance of do it with a single function?
>
> I do not see any list object. Lists and arrays (of which the two  
> dimensional ones are of type "matrix") are quite different basic  
> data structures in R. If you interchange the use of those terms you  
> will not get useful replies from R users. Those two object both  
> appear to be matrices and both should be handled by those functions.
>
>
>> 2009/8/3 David Winsemius <dwinsemius@comcast.net>
>>
>> On Aug 3, 2009, at 9:07 AM, Paulo Eduardo Cardoso wrote:
>>
>> Maybe a very basic question.
>> How can I get mean of a object like this
>>
>> str(object)
>> num [1:53, 1:2] 734 734 736 734 736 ...
>> - attr(*, "dimnames")=List of 2
>>  ..$ : NULL
>>  ..$ : chr [1:2] "x" "y"
>>
>> I want the mean of both x and y
>>
>> apply(object, 2, mean)
>>
>> or...
>>
>> colMeans(object)  # which will be faster
>>
>>
>> _______________
>> Paulo E. Cardoso
>>
>>        [[alternative HTML version deleted]]
>>
>> __________________________________________
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>
>
>
> -- 
> _______________
> Paulo E. Cardoso

David Winsemius, MD
Heritage Laboratories
West Hartford, CT


	[[alternative HTML version deleted]]


