Reputation: 157
I want to separate a column with tidyr to extract the grade level. The Column looks like this:
School.Name
School A ES
SchoolB MS
The is no standard way the schools are named, so when I use separate
separate(DF, School.Name,c("School.Name","Number","Grade Level")
I get this
School.Name Number Grade Level
School A ES
SchoolB MS NA
Is there a way to tell tidyr to read from the right rather that from the left
Upvotes: 0
Views: 136
Reputation: 2121
try ?separate
:
separate(DF, School.name, c("School.Name","Number","Grade Level"), fill = "left")
Then you got result like :
School.Name Number Grade Level
1 school A ES
2 <NA> schoolB MS
EDIT:
parameter fill
controls when separated characters size doesn't match column size, optional warn, right, left.
<
column sizee.g.
"schoolB MS" to C("A", "B", "C"), fill = "left" : <NA> schoolB MS
"schoolB MS" to C("A", "B", "C"), fill = "right" : schoolB MS <NA>
>
column sizee.g.
"schoolB MS" to C("A"), fill = "warn" : schoolB #default drop extra from the right
Upvotes: 2