0

Possible Duplicate:
Sorting and grouping data using R

I am a student that is learning R. I have already looked at some of the introduction stuff, that has been posted online. But I cant find a solution to my problem, which I'm sure is quite easy.

So say I have a vector

a <- c(1,2,6,5,3)

and I make a table of a,

> table(a)
a
1 2 3 5 6 
1 1 1 1 1 

I just wondering how to put zeroes in where the number is not there. I want to get something like:

> table(a)
a
1 2 3 4 5 6 
1 1 1 0 1 1 
Community
  • 1
  • 1
user1021000
  • 237
  • 1
  • 3
  • 8
  • 1
    A good first step is to look in the help file for `table`, got by typing `?table`. Hint: check the `See Also` section near the bottom of the help file... ;) – Josh O'Brien Dec 12 '11 at 22:53
  • 1
    Exact duplicate http://stackoverflow.com/a/8461190/903061, now off to edit that question's title so you would have had a chance to find it. – Gregor Thomas Dec 12 '11 at 22:53
  • 4
    @shujaa: If the OP can't find a question they asked yesterday, editing the title won't help. – Joshua Ulrich Dec 12 '11 at 23:06
  • @JoshuaUlrich Mostly I agree, but it took me a bit long to find it--skipped right past it in the search results--because its title was "Sorting and Grouping Data using R", which is an absolutely terrible title for this question. – Gregor Thomas Dec 13 '11 at 00:47
  • @shujaa: I agree with your change (and voted to approve it). It will surely help others, just not the OP. – Joshua Ulrich Dec 13 '11 at 00:51

0 Answers0