[英]Split column with tidyr with different lenghts
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 有没有办法告诉提迪尔从右边读而不是从左边读
try ?separate
: 尝试
?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.
参数
fill
控制何时分隔的字符大小与列大小不匹配,可选warn, right, left.
<
column size <
列大小 eg 例如
"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 size >
列大小 eg 例如
"schoolB MS" to C("A"), fill = "warn" : schoolB #default drop extra from the right
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.