PSYCH 018 Index > Introduction to R: Selecting Items; Conditions > Solution to Exercise

“You Do It!” (Solution)

> # set the score vector
> score <- c(47, 82, 65, 81, 39, 72, 89, 49, 52, 76)
> # set object middle to the median of the scores
> middle <- median(score)
> # display the value of middle
> middle
[1] 68.5
> # display summary of score vector
> summary(score)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  39.00   49.75   68.50   65.20   79.75   89.00 
> # select all scores less than the median
> score[score < middle]
[1] 47 65 39 49 52
> # select all scores less than the median
> # without using the "middle" object
> score[score < median(score)]
[1] 47 65 39 49 52

Return to Selecting Items and Conditions