That great! It's working! Thank you so much!
It is a pure magic which makes my head spin.
aggregate(.~ id, lapply(df, as.character), FUN =
function(x)paste(sort(x), collapse = ''), na.action = na.pass)
1. help says:
Note that ‘paste()’ coerces ‘NA_character_’, the character missing
value, to ‘"NA
Thank you for your efforts.
Although it is still not working, it feels like getting closer and
closer.
id cycle1 cycle2 cycle3
1 1cmfcmfcmf
2 2mfcmfcmfc
3 3 acfNA acfNA NAcfm
I really appreciate transformation from subsets ("c","m","f") to "cmf".
That was critica
Just change the FUN function:
aggregate(.~ id, lapply(df, as.character), FUN = function(x)paste(sort(x),
collapse = ''), na.action = na.pass)
On Fri, Jan 21, 2011 at 6:27 PM, Den wrote:
>
> Thank you for your efforts.
> Although it is still not working, it feels like getting closer and
> closer
Dear Henrique
Thank you again for helping me
Unfortunately, your code seems not to be working
> aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "")
id cycle1 cycle2 cycle3
1 1cmfcmfcmf
2 2mfcmfcmfc
3 3 cf cf cf
(letter 'a' missing in df[
correction:
aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "",
na.action = na.pass)
On Fri, Jan 21, 2011 at 5:56 PM, Henrique Dallazuanna wrote:
> Try this:
>
> aggregate(.~ id, lapply(replace(df, is.na(df), ''), as.character), FUN =
> paste, collapse = "", na.action = na.pass
Try this:
aggregate(.~ id, lapply(replace(df, is.na(df), ''), as.character), FUN =
paste, collapse = "", na.action = na.pass)
On Fri, Jan 21, 2011 at 5:45 PM, Den wrote:
> Dear Henrique
> Thank you again for helping me
> Unfortunately, your code seems not to be working
>
> > aggregate(.~ id, la
Try this:
aggregate(.~ id, lapply(test, as.character), FUN = paste, collapse = "")
On Fri, Jan 21, 2011 at 10:25 AM, Den wrote:
> Dear [R] people
> Could you please help with following data transformation.
> Any suggestions, hints, references and even guessing on performing any
> of the followi
Hi Denis,
#minimal example:
test<-as.data.frame(list(id=c(1,1,1,2,2,2), cycle1=c("c", "m", "f", "m",
"f", "c")))
#gettin your first cell of Result 1
paste(sort(test$cycle1[test$id==1]), collapse="")
Hope this helps for the first task ...
Moritz
__
Moritz Grenke
http://www
Denis,
Have a look at paste(), aggregate(), ddply() (from the plyr package) and melt()
and cast() (both from the reshape package).
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team
9 matches
Mail list logo