vendredi 17 février 2017

Applying if statement to data frame elements

Here is what i am trying to do: 1. Read in csv file 2. Create a column number 107 and copy values from column 67 based on the condition:' only copy values if row values in column 70 is "Yes"'

Code:

report <- read.csv("C:\\Users\\ha317981\\Desktop\\practice\\input.csv",  header=1)
for(i in 1:length(report[[70]])-1){ 
    if(report[[i, 70]] =="Yes"){
      report[[i,107]] <-report[[i, 67]]  
    }
    i<- i + 1
  }

Error: Error in [[.default(col, i, exact = exact) : attempt to select less than one element in get1index

Aucun commentaire:

Enregistrer un commentaire