0

I am very much a beginner in R Studio and programming in general and very often have the problem that I lack basic vocabulary to understand the help or the answers given here. If you are willing to help me, please keep in mind to use easy language...

I have a dataset spit out by a machine, that divides a range into many tiny little bins. E.g. the range of 2 to 3 is divided into up to 36 values (2.02,2.025,2.03 etc), each bin has a certain number of measured data in another column (s1noml). How do I sum up all values of the column "s1noml" that have e.g. a 2 before the period/comma in the bin-column? And afterwards automatically ( I guess via a loop?) all values with a 3 and then a 4 and so on

This is how the table looks like: enter image description here

I'm sorry if I use words incorrectly and that the question is so basic.

Looking forward to your help!

Luckilia
  • 3
  • 2

1 Answers1

0

I think this is more efficient and safe than writing a loop.

df$temp <- round(df$bin, 0)  # round to 0 decimal places, store in a temporary var
df2 <- aggregate(df$s1noml, by=list(df$temp), FUN=sum)  # sum by group in temp var

If this doesn't work quite right it'd be helpful to provide a reprex for us to work with.

cparmstrong
  • 799
  • 6
  • 23