df <- data.frame(a = 1:7,
f = factor(letters[1:7]))
transform(df,
r = recode(a, 1 -> 5,
2:3-> 2,
7 -> 6))
transform(df,
r = recode(a, 1 -> 5,
2:3-> 2,
7 -> 6,
otherwise="copy"))
transform(df,
r = recode(a, 1 -> 5,
2:3-> 2,
7 -> 6,
otherwise=100))
transform(df,
r = recode(a, 1 -> 5,
2:3 -> 2,
7 -> 6,
to.factor=TRUE))
transform(df,
r = recode(a, 1 -> "a",
2:3 -> "b",
7 -> "c"))
transform(df,
r = recode(a, 1 -> "a",
2:3 -> "b",
7 -> "c",
otherwise="z"))
transform(df,
r = recode(a, 1 -> "a",
2:3 -> "b",
7 -> "c",
otherwise="copy"))
transform(df,
r = recode(a, range(min,3) -> "a",
5 -> "b",
7 -> "d",
otherwise="copy"))
transform(df,
r = recode(a, range(max,3) -> "a",
1 -> "b",
2 -> "d",
otherwise="copy"))
transform(df,
r = recode(f, letters[1:3] -> "a",
letters[4:5] -> "b",
"f" -> "c"))
transform(df,
r = recode(f, letters[1:3] -> "a",
letters[4:5] -> "b",
"f" -> "c",
otherwise="copy"))
transform(df,
r = recode(f, letters[1:3] -> "a",
letters[4:5] -> "b",
"f" -> "c",
otherwise="z"))
Run the code above in your browser using DataLab