![]() ![]() variable label is automatically preserved library(dplyr) # recode 1 to 2 into 1 and 3 to 4 into 2 table(rec(efc$e42dep, rec = "1,2=1 3,4=2" ), useNA = "always" ) To replace NA's with specific value, recode_toįor re-shifting value ranges and ref_lvl to change the Value labels for new values can be assigned inside the recode pattern by writing the value label in square brackets after defining the new value in a recode pair, e.g. "rev" is a special token that reverses the value order (see 'Examples') direct value labelling "NA=1 3:5=NA" (recodes all NA into 1, and all values from 3 to 5 into NA in the new variable) "rev" NA values are allowed both as old and new value, e.g. will not be recoded, but copied, see 'Examples') NA's "3=1 1=2 else=copy" (recodes 3 into 1, 1 into 2 and all other values like 2, 4 or 5 etc. The "else"-token can be combined with copy, indicating that all remaining, not yet recoded values should stay the same (are copied from the original value), e.g. "3=1 1=2 else=3" (recodes 3 into 1, 1 into 2 and all other values into 3) "copy" "min:4=1 5:max=2" (recodes all values from minimum values of x to 4 into 1, and from 5 to maximum values of x into 2) "else"Īll other values, which have not been specified yet, are indicated by else, e.g. Minimum and maximum values are indicates by min (or lo) and max (or hi), e.g. 1:2.5=1 2.6:3=2 recodes 1 to 2.5 into 1 and 2.6 to 3 into 2, but 2.55 would not be recoded (since it's not included in any of the specified ranges) "min" and "max" "1:4=1 5:8=2" (recodes all values from 1 to 4 into 1, and from 5 to 8 into 2) value range for doublesįor double vectors (with fractional part), all values within the specified range are recoded e.g. "1,2=1 3,4=2" value rangeĪ value range is indicated by a colon, e.g. Multiple old values that should be recoded into a new single value may be separated with comma, e.g. The rec string has following syntax: recode pairsĮach recode pair has to be separated by a, e.g. Suffix = "", recoded variables will replace (overwrite) existing If x is a data frame,įor append = TRUE, x including the recoded variablesĪs new columns is returned if append = FALSE, only ![]() Variables for which predicate returns TRUE are selected. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |