1
votes

I'm trying to extract information from an excel spreadsheet that is not organized in columns but by rows. key points:

  1. the excel spreadsheet was converted to csv resulting in 2023 rows and 5 columns.
  2. read this file and converted in a data.frame, called "test".
  3. attempt to create a data.frame with 2 loops.
  4. result
 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'

very much appreciate your help..

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   

...

1

1 Answers

0
votes

I'm not sure that this will definitely address all of the warnings, but try adding the argument stringsAsFactors=FALSE to the end of the line where you create the data.frame.

Just by creating a character column you are using factors, which can't be modified with a simple assignment command. Your command should read x<-data.frame(name=character(920),date=numeric(920),ton=numeric(920),stringsAsFactors=FALSE).