> for(i in 1:length(name)){+ book.names[i]<-substring(name[i],17)#去掉书名前的空白+ others[i] <- substring(other[i],28,nchar(other[i])-4)+ temp<-strsplit(others[i],split = "/")[[1]]+ book.authors[i] = temp[1];+ book.Publishing_House[i] = temp[length(temp)-2]; + book.Publishing_date[i] = temp[length(temp)-1];+ book.price[i] = temp[length(temp)]; + book.scores [i] <- substring(score[i],45,nchar(score[i])-7)+ book.peoples[i]<-substring(people[i],45,nchar(people[i])-7)+ }Error in book.Publishing_House[i] <- temp[length(temp) - 2] : 更换参数长度为零
如果length(name) 比较大的话,还是尽量用向量计算吧,用for循环效率太低了。也建议使用正则表达式处理字符内容。比如,删掉名称前面的空格,可以用gsub("^ {1,6}","",name)这样的一句就可以删掉开头的1到6个空格,速度比用循环快多了