knavero
2012-Mar-02 20:51 UTC
[R] Noob question - Identity argument within aggregate function?
>aggregate(z, identity, mean)1 2 3 4 5 1.0 3.0 5.0 6.0 7.5> aggregate(z, mean)Error: length(time(x)) == length(by[[1]]) is not TRUE Can someone help me understand the error above and why "identity" is necessary to satisfy the error -- View this message in context: http://r.789695.n4.nabble.com/Noob-question-Identity-argument-within-aggregate-function-tp4439806p4439806.html Sent from the R help mailing list archive at Nabble.com.
Sarah Goslee
2012-Mar-02 22:35 UTC
[R] Noob question - Identity argument within aggregate function?
Hi, On Fri, Mar 2, 2012 at 3:51 PM, knavero <knavero at gmail.com> wrote:>>aggregate(z, identity, mean) > ?1 ? 2 ? 3 ? 4 ? 5 > 1.0 3.0 5.0 6.0 7.5 >> aggregate(z, mean) > Error: length(time(x)) == length(by[[1]]) is not TRUE > > Can someone help me understand the error above and why "identity" is > necessary to satisfy the errorWe can tell you to read ?aggregate and look at the order of the arguments. We can point out that aggregate(z, mean) is not the same as mean(z), and wonder what you are trying to accomplish with the former. We can ask for a reproducible example, and some idea of what you are trying to do. Sarah -- Sarah Goslee http://www.functionaldiversity.org
David Winsemius
2012-Mar-02 22:38 UTC
[R] Noob question - Identity argument within aggregate function?
On Mar 2, 2012, at 3:51 PM, knavero wrote:>> aggregate(z, identity, mean) > 1 2 3 4 5 > 1.0 3.0 5.0 6.0 7.5 >> aggregate(z, mean) > Error: length(time(x)) == length(by[[1]]) is not TRUEAs generally happens when you call a function and fail to provide enough arguments to fill up its formals list.> > Can someone help me understand the error above and why "identity" is > necessary to satisfy the errorWell on my machine it throws an error, probably because you failed to provide the requested code to create the objects you were working on. Is 'z' so sort of special classed object for which there is an aggregate method? Is 'identity' a list as expected by aggregate.default or aggregate.data.frame? It would be an unfortunate choice of an object name, since there is a function with that nam. -- David Winsemius, MD West Hartford, CT
knavero
2012-Mar-03 01:28 UTC
[R] Noob question - Identity argument within aggregate function?
z is a zoo object as a result from reading in the following series z = suppressWarnings(zoo(1:8), c(1, 2, 2, 2, 3, 4, 5, 5)) This is what z is in the aggregate function. So then that brings us to "aggregate(z, identity, tail, 1)". All I was trying to accomplish was trying to reproduce an example shown on the zoo faq. I've read ?aggregate via terminal and used "/identity" to search through the documentation for the specific term "identity". I'm just trying to understand what identity is used for because I do not understand the error statement. -- View this message in context: http://r.789695.n4.nabble.com/Noob-question-Identity-argument-within-aggregate-function-tp4439806p4440413.html Sent from the R help mailing list archive at Nabble.com.
knavero
2012-Mar-03 01:31 UTC
[R] Noob question - Identity argument within aggregate function?
Sorry, in regards to the previous post where I said aggregate(z, identity, tail, 1), replace it with aggregate(z, identity, mean) -- View this message in context: http://r.789695.n4.nabble.com/Noob-question-Identity-argument-within-aggregate-function-tp4439806p4440424.html Sent from the R help mailing list archive at Nabble.com.
Reasonably Related Threads
- Wrong output due to what I think might be a data type issue (zoo read in problem)
- question about user written function (newb question)
- aggregating specific parts in zoo index column to perform sliding average
- uneven vector length issue with read.zoo?
- read.zoo - combining two columns with date and time respectively into one index column?