我试图从excel电子表格中提取信息,该电子表格不按列而是按行排列。关键点:
There were 50 or more warnings (use warnings() to see the first 50) warning(extractor) Error in FUN(X[[1L]], ...) : cannot coerce type 'closure' to vector of type 'character'
非常感谢你的帮助..
extractor<-function(test){
##x<-data.frame(matrix(NA,nrow=920,ncol=3))
x<-data.frame(name=character(920),date=numeric(920),ton=numeric(920))
for (i in 1:920){
m<-11*i-9
{for(j in 1:5) {
x$name[i]=test[m,][1]
x$date[i]=test[m+j+2,][1]
x$ton[i]=test[m+j+2,][3]
}
}
}
test.csv looks like this:
XXXX-XXX-LHS-P1
2 XXXX-XXX-BHS-P1
3 Date blasted BLASTED (T) MUCKED (T) REM'G (T)
4 BLAST #1 0 0
5 BLAST #2 0.00 0
6 BLAST #3 0 0
7 BLAST #4 0 0
8 BLAST #5 0 0
9 TOTAL 0 0
10 % Mucked to Date 0 0 of design
11 REM'G TO BLAST 25419
12 XXXX-XXX-LHS-P1
13 XXXX-XXX-BHS-P1 10069 Ready? 0
14 Date blasted BLASTED (T) MUCKED (T) REM'G (T)
15 41556 BLAST #1 10069 10069
16 BLAST #2 0 0
17 BLAST #3 0 0
18 BLAST #4 0 0
19 BLAST #5 0 0
20 TOTAL 10069 9656 413
21 % Mucked to Date 0.958983017
22 REM'G TO BLAST 0
...
答案 0 :(得分:0)
我不确定这肯定会解决所有警告,但请尝试将参数stringsAsFactors=FALSE
添加到您创建data.frame
的行的末尾。
只需创建character
列即可使用因子,但无法使用简单的赋值命令进行修改。您的命令应为x<-data.frame(name=character(920),date=numeric(920),ton=numeric(920),stringsAsFactors=FALSE)
。