0

I want to create a table from a data frame that looks like:

         name             amount
         Mary              7065
         Anna              2604
         Emma              2003
    Elizabeth              1939
       Minnie              1746
     Margaret              1578

However, when I use the code

name1=data.frame(example1$name,example1$amount)
table(name1)

I get the error:

>  Error in tabulate(bin, pd) : cannot allocate vector of length 1206074100

Does this mean I first need to assign memory space, and if so how is this done for a data frame ?

The output for str(name1) :

> data.frame':  1724892 obs. of  2 variables:  $ example1.name  : Factor
> w/ 89925 levels "Aaron","Ab","Abbie",..: 1259 119 587 545 1330 1232
> 862 60 217 1642 ...  $ example1.amount: int  7065 2604 2003 1939 1746
> 1578 1472 1414 1320 1288 ...
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • Can you add the output of `str(name1)`? It looks like you are running into memory allocation issues because of the size of the object. – nrussell Oct 09 '14 at 16:21
  • I agree, I think it might be memory issues. I have edited my code above to include the str(name1) output – pumpkintea Oct 09 '14 at 16:25
  • 3
    What exactly are you trying to do? – Rich Scriven Oct 09 '14 at 16:44
  • Using `table` will tally, e.g., the number of times someone named `Mary` had amount `7065`... is that what you want? Or do you want to maybe sum or average the amounts by name? – Gregor Thomas Oct 09 '14 at 16:51
  • Another way to confirm what you want: run `table(head(name1))` to get a table based on the first 6 rows. Is that the sort of output you're looking for? – Gregor Thomas Oct 09 '14 at 17:00
  • @Gregor thanks for your reply. I am trying to convert my data frame into a table so I can tabulate the popularity of a name (for example, Mary) over each year. So the number of times Mary appears and the 'amount' for each time. – pumpkintea Oct 09 '14 at 17:10
  • Try `aggregate(amount~name,name1,sum)`. This will calculate the sum of the amounts for each name. – jlhoward Oct 09 '14 at 18:01
  • @pumpkintea There's many ways to do this, `aggregate` in base, or `data.table` or `dplyr` packages are popular and faster for bigger data. It's also a common question, e.g. http://stackoverflow.com/q/18387594/903061. – Gregor Thomas Oct 09 '14 at 19:01

0 Answers0