0

I am reading my data in by folder then pulling by a date range.

I am looking to summarize my data by a column but when doing so it is not combining them to produce less rows.

I am using the following code

 temptable <- temptable[ ,lapply(.SD, sum), by = .(INV_ITEM_ID),
                         .SDcols = c("Ext Sale", "Ext Total Cost")]

I have done this with subsets of my data and it can get it to work but not for the full data set.

Any ideas on why this is not summarizing correctly? I would provide a reproducible example but the code seems to work on that.

I can provide other details if needed.

An example of what is going on is lets say we have the following

INV_ITEM_ID, Ext Sale, Ext Total Cost
1234           8             4
1234           2             7
1233           6             4

When I run the above code that is how it returns to me instead of returning it like below

INV_ITEM_ID, Ext Sale, Ext Total Cost
1234           10            11
1233           6             4
J fast
  • 53
  • 8
  • Checked content of `INV_ITEM_ID`? You may have extra spaces somewhere (first thing I am stupidly thinking about -- there may be a more obvious tip) – Eric Lecoutre Jul 11 '18 at 16:33
  • i don't believe this is the case because none of them are combining together. – J fast Jul 11 '18 at 16:35
  • INV_ITEM_ID is a character type. Would i maybe need to change the type for it to combine to distinct values? – J fast Jul 11 '18 at 16:36
  • You'll need to make a reproducible example for a question like this. For guidance, I'd suggest https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 – Frank Jul 11 '18 at 16:49
  • Frank, it seems that if I provide a subset of my data the code works and combines the like values. It is when I use my full dataset that it is not working correctly. – J fast Jul 11 '18 at 17:06
  • I can show you my full code if that will help – J fast Jul 11 '18 at 17:06
  • Frank, could you use the iris dataset as an example and summarize by species? – J fast Jul 11 '18 at 17:59

0 Answers0