Dean Debrio
Dean Debrio

Reputation: 57

Incrementing variables from R queries

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:

enter image description here

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:

  1. Can I increment the 'i' inside that R queries
  2. Was my way is too complicated or there's other way to measure probability in R?

Sorry for lots of confusion, inneficiency, and holes, I hope I was clear enough here.

Upvotes: 0

Views: 31

Answers (1)

MonJeanJean
MonJeanJean

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

Related Questions