水平误差<-(* tmp *,value = as.character(levels)):重复了因子水平[3]。如何解决这个问题?

时间:2019-07-05 08:45:22

标签: r dataframe

数据可用here! 我正在尝试以分层方式构造此数据框。问题出在“底漆”因素上,因为它不适用于所有级别的“胶粘剂”,换句话说,胶粘剂:SB1-XT只有“是”底漆,而其他胶粘剂有“是”和“否” '

'data.frame':   400 obs. of  7 variables:
 $ data_SBS  : num  2.41 11.81 11.02 8.07 6.81 ...
 $ group     : num  5 5 5 5 5 5 5 5 5 5 ...
 $ data_block: num  1 2 3 4 5 6 7 8 9 10 ...
 $ Treatment : Factor w/ 4 levels "AM","CJ","HF",..: 4 4 4 4 4 4 4 4 4 4 ...
 $ Adhesive  : Factor w/ 3 levels "ADH","SB1-XT",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Aging     : Factor w/ 2 levels "1w","3m": 1 1 1 1 1 1 1 1 1 1 ...
 $ Primer    : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...

我尝试了几种选择,下面的代码工作正常,除了添加因子'Primer'之后无法重新排序数据框

Data$Adhesive<-factor(Data$Adhesive, c("ADH","SBU","SB1-XT"))
Data$Adhgroup <- as.factor(paste(as.character(Data$Adhesive),as.character(Data$Treatment), sep="_")) 
levels(Data$Adhgroup)
Data$Adhgroup<-factor(Data$Adhgroup, paste(rep (levels(Data$Adhesive),each=4),rep(levels(Data$Treatment)), sep="_"))
Data$biggroup <- as.factor(paste(as.character(Data$Adhgroup),as.character(Data$Aging), sep="_")) 
Data$biggroup<-factor(Data$biggroup, paste(rep(levels(Data$Adhgroup),each=2),rep(levels(Data$Aging)), sep="_"))
Data$Adh_Bondgroup <- as.factor(paste(as.character(Data$biggroup),as.character(Data$Primer), sep="_")) 
 Data$Adh_Bondgroup<-factor(Data$Adh_Bondgroup, paste(rep(levels(Data$biggroup),each=8)),rep(levels(Data$Primer)), sep="_"))
levels(Data$Adh_Bondgroup)

运行最后一个代码时,出现错误消息:

levels<-*tmp*中的错误,值= as.character(levels)):   因子水平[3]被复制。 如何解决? 预先谢谢你

0 个答案:

没有答案