Reputation: 57
Hi so I am new in R and kind of don't know what I'm looking for. I want to measure probability of each frequency of a dust concentration so I need to divide each frequency to whole total of dust concentration frequency. By then I can continue by looking for CDF and PMF of the dust concentration.
So I have a dust probability data that has two column(Dust Concentration and its Frequencies) and it looks like this:
In my first thought, I have to increment i on this line of R queries
dustProb[i, "Frekuensi"]
that should've take specific frequency in row i so I can sum all frequency queried from it after getting that with for loops like this.
# the dataset is called dustData here
# dustFrequencies = dustData[i, "Frekuensi"]
for(i in dustFrequencies){
print(dustFrequencies)
}
The print() part supposed to be where I sum all the variables earned through that incremented queries.
My question is:
Sorry for lots of confusion, inneficiency, and holes, I hope I was clear enough here.
Upvotes: 0
Views: 31
Reputation: 2906
Using loops in R isn't very tidy-freindly. You can do:
library(dplyr)
dustData <- dustData %>%
mutate(probabilities = Frekuensi/sum(Frekuensi))
The new column is the frenquency divided by the sum of all frequencies, for each dust concentration.
Upvotes: 1