Graphics Reference
In-Depth Information
include.lowest=TRUE . In this example, this would result in 0 values going into the small cat-
egory; otherwise, 0 would be coded as NA .
If you want the categories to be closed on the left and open on the right, set right = FALSE :
cut(pg$weight, breaks = c( 0 , 5 , 6 , Inf), right = FALSE
FALSE )
See Also
To recode a categorical variable to another categorical variable, see Recoding a Categorical Vari-
able to Another Categorical Variable .
Transforming Variables
Problem
You want to transform a variable in a data frame.
Solution
Reference the new column with the $ operator, and assign some values to it. For this example,
we'll use a copy of the heightweight data set:
library(gcookbook) # For the data set
# Make a copy of the data
hw <- heightweight
hw
sex ageYear ageMonth heightIn weightLb
f
11.92
143
56.3
85.0
f
12.92
155
62.3
105.0
...
m
13.92
167
62.0
107.5
m
12.58
151
59.3
87.0
This will convert heightIn to centimeters and store it in a new column, heightCm :
hw$heightCm <- hw$heightIn * 2.54
hw
sex ageYear ageMonth heightIn weightLb heightCm
f
11.92
143
56.3
85.0 143.002
f
12.92
155
62.3
105.0 158.242
...
Search WWH ::




Custom Search