Get startedGet started for free

Scaling variables

The next step is wrangling the data into a format that is easy to analyze. We will wrangle our data for the next few exercises.

A neat thing about R is that may operations are vectorized. It means that a single operation can affect all elements of a vector. This is often convenient.

The column Attitude in lrn14 is a sum of 10 questions related to students attitude towards statistics, each measured on the Likert scale (1-5). Here we'll scale the combination variable back to the 1-5 scale.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Execute the example codes to see how vectorized division works
  • Use vector division to create a new column attitude in the lrn14 data frame, where each observation of Attitude is scaled back to the original scale of the questions, by dividing it with the number of questions.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

#lrn14 is available

# divide each number in a vector
c(1,2,3,4,5) / 2

# print the "Attitude" column vector of the lrn14 data
lrn14$Attitude

# divide each number in the column vector
lrn14$Attitude / 10

# create column 'attitude' by scaling the column "Attitude"
lrn14$attitude <- "change me!"
Edit and Run Code