[R] question about using _apply and/or aggregate functions

David Winsemius dwinsemius at comcast.net
Tue Jun 23 02:11:19 CEST 2009


On Jun 22, 2009, at 7:55 PM, David Winsemius wrote:

>
> On Jun 22, 2009, at 6:16 PM, Clifford Long wrote:
>
>> Hi David,
>>
>> I appreciate the advice.  I had coerced 'list4' to as.list, but  
>> forgot
>> to specify "list=()" in the call to aggregate.  I made the  
>> correction,
>> and now get the following:
>>
>>> slope.mult = simarray[,1]
>>> adj.slope.value = simarray[,2]
>>> adj.slope.level = simarray[,2]
>>> qc.run.violation = simarray[,5]
>>> simarray.part = cbind(slope.mult, adj.slope.value,  
>>> qc.run.violation, adj.slope.level)
>>> list4 = as.list(simarray.part[,4])
>>> agg.result = aggregate(simarray.part[,3], by=list(list4), FUN =  
>>> mean)
>> Error in sort.list(unique.default(x), na.last = TRUE) :
>> 'x' must be atomic for 'sort.list'
>> Have you called 'sort' on a list?
>>
>> ... I'm not sure what this means that I've done wrong.  I did check
>> 'list4' using "is.list", and get "TRUE" back as an answer, so feel
>> that my mistake is some other fundamental aspect of R that I'm  
>> failing
>> to grasp.
>>
>> To your note on 'tapply' ... I did try this as well (actually, tried
>> it first) with no initial success.  On your recommendation, I gave
>> tapply another go, and get something recognizable:
>>
>> vtt = tapply(simarray.part[,3], simarray.part[,2], mean)


snipped other stuff...

>
>
>> I would like to be able to plot
>> one against the other.
>
> plot(names(vtt), vtt)

Or perhaps:

plot(as.numeric(names(vtt)), vtt)

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list