我已经根据我之前提出的问题修改了下面的代码:
Input_Data <- read.csv("http://dl.dropbox.com/u/58164604/Input_Data.csv", row.names=1, stringsAsFactors = FALSE)
TPop<-Input_Data[1]
TPopCount <- TPop[, 1]
TPopSum <- sum(TPopCount)
OACRaw<-Input_Data[,4:ncol(Input_Data)]
OACRawCount <-ncol(OACRaw)
OA_Percentage <- TPopCount/TPopSum * 100
Data_Per_Row <- OACRaw/matrix(rep(TPopCount, each=OACRawCount), ncol=OACRawCount, byrow=T)*100
Data_Index_Row <- Data_Per_Row/OA_Percentage * 100
names(Data_Per_Row) <- names(Data_Index_Row) <- names(OACRaw)
但是,当我尝试让它适用于更大的数据集(186 列和超过 180,000 行)时,它会出现以下错误:
Error in FUN(left, right) : non-numeric argument to binary operator
但是,当相同的代码运行较小的数据集(46 列和 180,00 行)时,它可以正常工作:
Input_Data <- read.csv("http://dl.dropbox.com/u/58164604/Input_Data.csv", row.names=1, stringsAsFactors = FALSE)
TPop<-Input_Data[1]
TPopCount <- TPop[, 1]
TPopSum <- sum(TPopCount)
OACRaw<-Input_Data[,4:50]
OACRawCount <-ncol(OACRaw)
OA_Percentage <- TPopCount/TPopSum * 100
Data_Per_Row <- OACRaw/matrix(rep(TPopCount, each=OACRawCount), ncol=OACRawCount, byrow=T)*100
Data_Index_Row <- Data_Per_Row/OA_Percentage * 100
names(Data_Per_Row) <- names(Data_Index_Row) <- names(OACRaw)
谁能解释为什么会这样以及如何让这段代码在更大的数据集上工作?谢谢