# Adding missing values while comparing two vector..

#### tsukiko

##### New Member
Let say i have

Code:
aa=c(0,2,3,5)
freq=c(13,4,5,2)
table_aa=cbind(aa,freq)
But, I want to have the final output something like:

Code:
table_aa
aa freq
0 13
[COLOR="red"]1  0[/COLOR]
2  4
3  5
[COLOR="red"]4  0[/COLOR]
5  2
So, i want to "automatically" generate for any value aa with zero frequency, i want to add the missing value of aa and its zero frequency into the table. So, i dont have to manually type and check this step again and again whenever i change the value of aa. Simply say, i want to add those missing line in table_aa generated by table(aa).

P/S: Actually table_aa is just a frequency table of aa which can be obtained using table(aa). But, as an example here, i simply set their values.

#### Mike White

##### TS Contributor
I am not sure how this question differs from your previous query on Count Frequency which received several solutions that appear to do what you want.

#### Link

##### Ninja say what!?!
One solution is to create a sequence with the seq command. Then to merge the values into the sequence and set any missing values to 0.

#### tsukiko

##### New Member
Yes, i already check that thread, i tried the factor suggestion some time ago.. And since i want to extract the freq values later, saving it using as.data.frame actually solve my problem. My codes are getting longer and i lost my sight about the line where i construct the table. So, when i have entries with zero frequency i keep typing the frequency manually and find it's just tedious. Sorry for double posting and any inconvenience caused.

P/S: This thread should be merged with http://www.talkstats.com/showthread.php/17362-Count-frequency?p=49944&highlight=#post49944