On Mar 3, 2016, at 4:14 PM, Ista Zahn <istazahn at gmail.com> wrote:
Like this?
x <- factor("001-014")
y <- substr(as.character(x), 1, 3)
Best,
Ista
On Thu, Mar 3, 2016 at 3:18 PM, KMNanus <kmnanus at gmail.com> wrote:
I have a factor variable that is 6 digits and hyphenated. For example, 001-014.
I need to extract the first 3 digits to a new variable using mutate in dplyr - in this case 001 - but can?t find a function to do it.
substr will do this for character strings, but I need the variable to remain as a factor.
Is there an R function or workaround to do this?
Ken
kmnanus at gmail.com
914-450-0816 (tel)
347-730-4813 (fax)