0

I need to calculate frequencies, the following code I'm using is working but I need the breaks to include the ages rounded to 3 digits, so that the frequency of a given age falls into the right break/class

freqNT = NT$Age
range(freqNT)
#[1] 1.251826 6.626601
breaks_NT = seq(1, max(NT$newAge), by=0.2) 
freq.cutNT = cut(freqNT, breaks=breaks_NT, right=FALSE, include.lowest = TRUE, order_result=T)
freq.freqNT = table(freq.cutNT)
freq.freqNT 
freq.cutNT
cbind(freq.freqNT)
freq.freqNT

For example, I need the age 6.626601 to fall within the break [6.4,6.6] With it rounded to 6.627

  • 1
    you might search the `findInterval` function – MichaelChirico May 17 '18 at 12:01
  • 1
    But 6.627 _is not_ between 6.4 and 6.6 !! – G5W May 17 '18 at 12:48
  • Indeed but with seq(1, max(NT$newAge), by=0.2), the last break is [6.4,6.6] If someone is keen to help me I can send my file with the data; I would appreciate a looot because I'm really running out of time and I'm extremely tired and desperate as I need to solve this to finally finish my analysis.. my email is catarinacamposferreira@gmail.com I will be eternally grateful and I can add your name in my acknowledgements of the thesis – Catarina Ferreira May 17 '18 at 13:04
  • But as @G5W stated, 6.627 does not fall between 6.4 and 6.6. You may want to add a `(6.6, ∞]` interval – csgroen May 17 '18 at 13:39
  • I'm sorry but how do I do that? I defined on the breaks to be until the max! by **max(NT$newAge)** – Catarina Ferreira May 17 '18 at 13:45
  • `breaks_NT = c(-Inf, seq(1, max(NT$newAge), by=0.2), Inf) ` – G5W May 17 '18 at 14:11

0 Answers0