시작하기무료로 시작하기

Parsing age and gender into pieces

To finish up, you need to pull out the individual pieces and tidy them into usable variables.

There are a few ways you could get at one piece: you could extract out the piece you need, you could replace everything that isn't the piece you need with "", or you could try to split into the pieces you need. You'll try a few of these in this exercise and you'll see yet another way in the next chapter. For the first option, stringr has a nice convenience function, str_remove(), that works like str_replace() with replacement = "".

One benefit of building up your pattern in pieces is you already have patterns for each part that you can reuse now.

이 연습은 강의의 일부입니다

String Manipulation with stringr in R

강의 보기

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# age_gender, age, gender, unit are pre-defined
ls.str()

# Extract age and make numeric
___
코드 편집 및 실행