Re: [R] Data Manipulation, add frequency index

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 08 Nov 2008 05:57:21 -0500

See ?ave and ?seq_along

DF <- data.frame(Name = c("Mary", "Mary", "Mary", "Sam", "Sam",

   "John", "John", "John", "John"), stringsAsFactors = FALSE) DF$index <- ave(1:nrow(DF), DF$Name, FUN = seq_along)

On Sat, Nov 8, 2008 at 5:43 AM, jie feng <jiefeng222_at_gmail.com> 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
>
>
> Mary
> Mary
> Mary
> Sam
> Sam
> John
> John
> John
> John
>
> 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?
>
> Best
>
> Jie
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 08 Nov 2008 - 10:59:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 08 Nov 2008 - 11:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive