0

I don't know how to word the title exactly, so I will just do my best to explain below... Sorry in advance for the .csv format.

I have the following example dataset:

print(data)

      ID Tag  Flowers
1     1  6871  1
2     2  6750  1
3     3  6859  1
4     4  6767  1
5     5  6747  1
6     6  6261  1
7     7  6750  1
8     8  6767  1
9     9  6812  1
10   10  6746  1
11   11  6496  4
12   12  6497  1
13   13  6495  4
14   14  6481  1
15   15  6485  1

Notice that in Lines 2 and 7, the tag 6750 appears twice. I observed one flower on plant number 6750 on two separate days, equaling two flowers in its lifetime. Basically, I want to add every flower that occurs for tag 6750, tag 6767, etc throughout ~100 rows. Each tag appears more than once, usually around 4 or 5 times.

I feel like I need to apply the unlist function here, but I'm a little bit lost as to how I should do so.

Adam
  • 313
  • 1
  • 3
  • 12
  • 1
    It looks like your data-import did not go well (as your data still has commas in them, and only appears to have one column). Is there anything you have already tried to get the result you want? – Heroka Aug 04 '15 at 09:26
  • `library(dplyr) group_by(data,Tag) %>% summarise(count=sum(Flowers))` – scoa Aug 04 '15 at 09:28

1 Answers1

1

Without any extra packages, you can use function aggregate():

res<-aggregate(data$Flowers, list(data$Tag), sum)

This calculates a sum of the values in Flowers column for every value in the Tag column.