&引用;警告:值太多(太少)”;用于在R中使用tidyr包

&引用;警告:值太多(太少)”;用于在R中使用tidyr包,r,tidyr,R,Tidyr,我有以下数据集D7 name sex_age eye_color height 1 J M.34 Other 61 2 A F.55 Blue 59 3 T M.76 Brown 51 4 D F.19 Other 57 我想将列sex\u age分为sex列和age列,因此我键入 separate(D7,sex_age,c('sex','age'),sep='.') 但它会产生

我有以下数据集
D7

name sex_age eye_color height
1    J    M.34     Other     61
2    A    F.55      Blue     59
3    T    M.76     Brown     51
4    D    F.19     Other     57
我想将列
sex\u age
分为
sex
列和
age
列,因此我键入

separate(D7,sex_age,c('sex','age'),sep='.')
但它会产生

name sex age eye_color height
1    J             Other     61
2    A              Blue     59
3    T             Brown     51
4    D             Other     57
Warning message:
Too many values at 4 locations: 1, 2, 3, 4 
另外,当我将原始数据集
D7
修改为
D8

name sex_age eye_color height
1    J    M_34     Other     61
2    A    F_55      Blue     59
3    T    M_76     Brown     51
4    D    F_19     Other     57
我输入
D7%>%分开(sex\u-age,c('sex','age'),sep=“”)

name  sex  age eye_color height
1    J M.34 <NA>     Other     61
2    A F.55 <NA>      Blue     59
3    T M.76 <NA>     Brown     51
4    D F.19 <NA>     Other     57
Warning message:
Too few values at 4 locations: 1, 2, 3, 4 
姓名性别年龄眼睛颜色高度
1 J M.34其他61
2 A F.55蓝色59
3 T M.76棕色51
4 D F.19其他57
警告信息:
4个位置的值太少:1、2、3、4

我是否误用了
separate
功能?我很困惑。谢谢您的建议。

由于
sep=
参数考虑了regex和
是一个特殊字符,因此我们需要在这些特殊字符之前加上
\
,以便将它们作为普通字符读取

separate(df, sex_age, into = c("sex", "age"), sep = "\\.")

由于
sep=
参数考虑了正则表达式,并且
是一个特殊字符,因此我们需要在这些特殊字符之前加上
\
,以便将它们作为普通字符读取

separate(df, sex_age, into = c("sex", "age"), sep = "\\.")

再见,再见,谢谢!我不熟悉正则表达式,现在正在学习它。但是由
\uuu
生成的警告呢?我不知道在regex中有特殊的含义。即使加上“\\”也不能消除警告。谢谢!我不熟悉正则表达式,现在正在学习它。但是由
\uuu
生成的警告呢?我不知道在regex中有特殊的含义。即使加上“\\”也不能消除警告。