'I want to split this data into two columns one contains the first part of integer and one contain the second part chr
emp_no first_name age
10001 Georgi 55
10002 Bezalel 44
10003 Parto 52
10004 Chirstian 50
10005 Kyoichi 22
10006 Anneke 25
10007 Tzvetan 82
10008 Saniya 55y
10009 Sumant 5y
10010 Duangkaew 10y 8m
10011 Mary 44y
10012 Patricio 22y 8m
Solution 1:[1]
You can use tidyr::separate:
df %>%
mutate(age = gsub("[A-Za-z]", "", age)) %>%
separate(age, into = c("year", "month"))
emp_no first_name year month
1 10001 Georgi 55 <NA>
2 10002 Bezalel 44 <NA>
3 10003 Parto 52 <NA>
4 10004 Chirstian 50 <NA>
5 10005 Kyoichi 22 <NA>
6 10006 Anneke 25 <NA>
7 10007 Tzvetan 82 <NA>
8 10008 Saniya 55 <NA>
9 10009 Sumant 5 <NA>
10 10010 Duangkaew 10 8
11 10011 Mary 44 <NA>
12 10012 Patricio 22 8
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maël |
