我想用tidyr分隔一列来提取年级。专栏看起来像这样:
School.Name
School A ES
SchoolB MS
这不是学校命名的标准方式,所以当我使用单独的
时separate(DF, School.Name,c("School.Name","Number","Grade Level")
我明白了
School.Name Number Grade Level
School A ES
SchoolB MS NA
有没有办法告诉tidyr从右边读取而不是从左边读取
答案 0 :(得分:2)
尝试?separate
:
separate(DF, School.name, c("School.Name","Number","Grade Level"), fill = "left")
然后你得到的结果如下:
School.Name Number Grade Level
1 school A ES
2 <NA> schoolB MS
修改强>
参数fill
控制何时分隔的字符大小与列大小不匹配,可选warn, right, left.
<
列大小e.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>
>
列大小e.g。
"schoolB MS" to C("A"), fill = "warn" : schoolB #default drop extra from the right