thank you everyone. how can I not be aware of the existence of ave()? I try
the following:
tapply(data$value, data$level, rank). However, I have a very difficult time
merging the resulting rank variable back to the original data frame.
thanks a lot!
--
View this message in context:
http://r.78
Hi:
Another angle. Calling your example data frame df,
df <- transform(df, Rank = with(df, ave(value, level, FUN = rank)))
df[with(df, order(level, value)), ]
value level Rank
3 2 A1
1 4 A2
2 5 A3
5 9 B1
410 B2
634 B3
9
On May 27, 2011, at 3:12 PM, xin wei wrote:
hello, I have the following data manipulation issue. the following
is the
sample data:
value level
4 A
5 A
2 A
10 B
9 B
34 B
100 C
34 C
101C.
I hope to get the following result:
value level rank
2 A
Hi,
This seems to work (although I have this sense that I am missing
something, but I cannot put my finger on it). There are undoubtedly
other ways:
## data in a form ready for copy and pasting (created using dput() )
dat <- structure(list(value = c(4L, 5L, 2L, 10L, 9L, 34L, 100L, 34L,
101L), l
hello, I have the following data manipulation issue. the following is the
sample data:
value level
4 A
5 A
2 A
10 B
9 B
34 B
100 C
34 C
101C.
I hope to get the following result:
value level rank
2 A 1
4 A 2
5 A 3
9
5 matches
Mail list logo