Graphics Reference
In-Depth Information
weight group weightcat treatment newcol
4.17 ctrl small no no_small
5.58 ctrl large no no_large
4.81 trt1 small yes yes
4.17 trt1 small yes yes
6.31 trt2 large yes yes
5.12 trt2 large yes yes
It's also possible to combine two columns into one using the interaction() function, which
appends the values with a "." in between. This combines the weightcat and treatment
columns into a new column, weighttrt :
pg$weighttrt <- interaction(pg$weightcat, pg$treatment)
pg
weight group weightcat treatment newcol weighttrt
4.17 ctrl small no no_small small.no
5.58 ctrl large no no_large large.no
4.81 trt1 small yes yes small.yes
4.17 trt1 small yes yes small.yes
6.31 trt2 large yes yes large.yes
5.12 trt2 large yes yes large.yes
See Also
For more on renaming factor levels, see Changing the Names of Factor Levels .
See Recoding a Continuous Variable to a Categorical Variable for recoding continuous values to
categorical values.
Recoding a Continuous Variable to a Categorical
Variable
Problem
You want to recode a continuous variable to another variable.
Solution
For the examples here, we'll use a subset of the PlantGrowth data set.
# Work on a subset of the PlantGrowth data set
pg <- PlantGrowth[c( 1 , 2 , 11 , 21 , 22 ), ]
pg
Search WWH ::




Custom Search