Error in match.names(clabs, names(xi)) : names do not match previous names

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error in match.names(clabs, names(xi)) : names do not match previous names相关的知识,希望对你有一定的参考价值。

Error in match.names(clabs, names(xi)) : names do not match previous names

目录

Error in match.names(clabs, names(xi)) : names do not match previous names

问题:

解决:

完整问题:


问题:

#两个dataframe的名称不同,没法纵向合并;

#横向合并是没有问题的

#create and view first data frame
df1 <- data.frame(var1=c(1, 3, 3, 4, 5),
                  var2=c(7, 7, 8, 3, 2))

df1

#create and view first second frame 
df2 <- data.frame(var3=c(3, 3, 6, 6, 8),
                  var4=c(1, 1, 2, 8, 9))

df2

#attempt to row bind the two data frames
rbind(df1, df2)

解决:

#检查名称是否相同

#check if column names are identical between two data frames
identical(names(df1), names(df2))

[1] FALSE

#重命名之后再合并OK

#define two data frames
df1 <- data.frame(var1=c(1, 3, 3, 4, 5),
                  var2=c(7, 7, 8, 3, 2))

df2 <- data.frame(var3=c(3, 3, 6, 6, 8),
                  var4=c(1, 1, 2, 8, 9))

#rename second data frame columns
names(df2) <- c('var1', 'var2')

#row bind the two data frames
rbind(df1, df2)

完整问题:


> #create and view first data frame
> df1 <- data.frame(var1=c(1, 3, 3, 4, 5),
+                   var2=c(7, 7, 8, 3, 2))

> df1
  var1 var2
1    1    7
2    3    7
3    3    8
4    4    3
5    5    2

> #create and view first second frame 
> df2 <- data.frame(var3=c(3, 3, 6, 6, 8),
+                   var4=c(1, 1, 2, 8, 9))

> df2
  var3 var4
1    3    1
2    3    1
3    6    2
4    6    8
5    8    9

> #attempt to row bind the two data frames
> rbind(df1, df2)
Error in match.names(clabs, names(xi)) : 名字同原来已有的名字不相对

以上是关于Error in match.names(clabs, names(xi)) : names do not match previous names的主要内容,如果未能解决你的问题,请参考以下文章

[Elasticsearch] 邻近匹配 - 多值字段,邻近程度与相关度

[RxJS] Error Handling in RxJS

# Error in colSums(iris) : ‘x‘ must be numeric,# Error in rowSums(iris) : ‘x‘ must be numeric

1064 - syntax error, error in :'Id`) USING BTREE

ERROR 1064 (42000): You have an error in your SQL syntax...

Error in eval(family$initialize) : y值必需满足0 <= y <= 1Error in eval(family$initialize) : y values mus