[R] Data Manipulation, add frequency index
d.rizopoulos at erasmusmc.nl
Sat Nov 8 11:56:14 CET 2008
one way is with ave(), e.g.,
dat <- data.frame(name = rep(c("Mary", "Sam", "John"), c(3,2,4)))
dat$freq <- ave(seq_along(dat$name), dat$name, FUN = seq_along)
I hope it helps.
jie feng wrote:
> Hi, there,
> I have a simple data manipulation question for you. Thank you for your help!
> Suppose that I have this data about people appearing in a class
> Then I want to find out what exact time(s) the student appears at the
> moment such as
> Mary 1
> Mary 2
> Mary 3
> Sam 1
> Sam 2
> John 1
> John 2
> John 3
> John 4
> the fifth row shows tha Sam show the second times at the that moment.
> How can I manipulate the data in this way. Suppose that now I just have
> "name" variable and want to add a colume of frequency?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Department of Biostatistics
Erasmus Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
More information about the R-help