楼主: carrie11925
2489 0

[问答] 一个R的去重复程序 老是显示变量找不到 求大神指点 [推广有奖]

  • 0关注
  • 0粉丝

初中生

57%

还不是VIP/贵宾

-

威望
0
论坛币
5 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
50 点
帖子
1
精华
0
在线时间
32 小时
注册时间
2015-10-8
最后登录
2021-11-3

楼主
carrie11925 发表于 2016-10-14 18:27:44 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
> if (!require("xlsx")) install.packages("xlsx")
>  vec <- c( )
>  n = 0
> for (i in 1:12)
+   {
+        df1 <- read.xlsx(file="C:\收集链接.xls",sheetIndex=i,encoding='UTF-8')  #读取excel文件
>        df2 <- as.matrix(df1[ ,1])[apply(as.matrix(df1[ ,1]),1,nchar)>40,] #df2 is a vector
Error in as.matrix(df1[, 1]) : 找不到对象'df1'
>        df3 <- apply(as.matrix(df2),1,function(x) strsplit(x,'\\?')[[1]][1])
Error in as.matrix(df2) : 找不到对象'df2'
>           
>        index1 <- duplicated(df3)
Error in duplicated(df3) : 找不到对象'df3'
>        if (sum(index1)==0) {
+         cat(paste('sheet',i,'内没有重复项!',sep=''),file="D:/重复.txt",append=TRUE,"\n")
+         }else{
+          cat(paste('sheet',i,'内有重复项:',sep=''),file="D:/重复.txt",append=TRUE,"\n")
+         write.table(df3[index1],file="D:/重复.txt",row.names=FALSE,col.names=FALSE,append=TRUE)#写出重复项
+         }
错误: 找不到对象'index1'
>         
>      
>        vec <- c(vec,df3[!index1])
错误: 找不到对象'df3'
>        index2 <- duplicated(vec)
>        if (sum(index2)==0) {
+         cat(paste('sheet',i,'与前面无重复项!',sep=''),file="D:/重复.txt",append=TRUE,"\n")
+         }else{
+          cat(paste('sheet',i,'与前面有重复项:',sep=''),file="D:/重复.txt",append=TRUE,"\n")
+         write.table(vec[index2],file="D:/重复.txt",row.names=FALSE,col.names=FALSE,append=TRUE)#写出重复项
+         }
Error in file(file, ifelse(append, "a", "w")) : 无法打开链结
此外: Warning message:
In file(file, ifelse(append, "a", "w")) :
  无法打开文件'D:/重复.txt': Permission denied
>
>        index3 <- index2[(n+1):length(index2)]
>        filter <- df3[!index1][!index3]  # filter <- df1[!index1, ][!index3, ]
错误: 找不到对象'df3'
>        write.xlsx(filter,file="D:/去重复.xls",sheetName=paste('sheet',i,sep=''),append=TRUE) #写出去重复项
Error in as.data.frame.default(x[[i]], optional = TRUE) :
  cannot coerce class ""function"" to a data.frame
>
>        vec <- vec[!index2]
>        n <- length(vec)
>       }


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:permission Packages package install Mission require 程序 file

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-6 03:19