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.
Este ejercicio forma parte del curso
Helsinki Open Data Science
Instrucciones del ejercicio
- Execute the example codes to see how vectorized division works
- Use vector division to create a new column
attitudein thelrn14data frame, where each observation ofAttitudeis scaled back to the original scale of the questions, by dividing it with the number of questions.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
#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!"