Percentile calculations

I have issues getting this R code to run. I want to compute quantiles of SCORE1 below and then categorize score2 by quantiles of score1 (0.2, 0.4, 0.6, 0.8). However, the 2 R codes below do not run properly. Could you help figure out what the issue is?

df <- data.frame(ID = 1:10, Score1 = c(78, 82, 65, 90, 72, 88, 55, 67, 92, 81), Score2 = c(89, 95, 76, 82, 91, 85, 72, 68, 97, 88))

df$quartile <- with(df, factor(findInterval (score1, c(-Inf,quantile(score1, probs=c(.2,.4,.6,.8)),Inf),na.rm=TRUE), labels=c('Q1','q2','Q3','Q4'.'Q5')))

df$quartile <- with(df, cut(score1, breaks=quantile(score1, probs=seq(0,1, by .2),na.rm=TRUE), include.lowest=TRUE))

you have various issues. inconsistent capitalisation ; ie. score1 != Score1
in the first with() code, you have replaced a comma with a fullstop
in the second with() code, you have omitted an equal sign between by and .2
The first with() code also has brackets in odd places. I assume you intended na.rm=TRUE to be a quantile param, but you havent it written it to be so.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.