Wednesday, August 31, 2011

Count the number observations for a specified Variable

Data that is not numerical can be a challenge to use in R - I have been finding this out over the last few days. The example data is for a venue which records the days on which they hold a gigt. Example:
Gig#     Day
1       Mon
2       Mon
3       Wed
4       Sat
5       Fri

At the moment, all I want to do is be able to count the number of gigs (Ofcourse, the answer is 5 here, but I need R to be able to count that correctly too).

Solution: use table(). Assume the data has been imported to the variable of your choice, 'data'. By specifying the variable you wish to look at, simply use $variable-of-interest
> table(data)
> table(data$Day)

The output should look something like this - this is a dataset I am working on atm.
      Day
Year   Fri Mon Sat Sun Thu Tue Wed
  2010  11   1  16   8   1   1   5
  2011  10   1  11   5   1   1   2

To be continued...

No comments:

Post a Comment