Home > front end >  conversion to ASCII number
conversion to ASCII number

Time:10-19

    > for (i in 1:(ncol(crypto$name))) {
        if (is.character(crypto$name[, i])==TRUE){
          for(j in 1:nrow(crypto$name)) {
            ascis <- as.numeric(charToRaw(crypto$name[j, i]))
            name[ j, i] <- sum(ascis)
          }
        }
        crypto$name[,i] <- as.numeric(crypto$name[,i])
      }
    Error in 1:(ncol(crypto$name)) : argument of length 0
    > 

I have been trying to change two columns in my dataset to ASCII but getting the error. i am at loss please I need help

CodePudding user response:

Change ncol to nrow. You need to loop over the rows and not columns.

The other parts also have a couple of syntax errors.

For instance, crypto$name[, i] is incorrect. It should be crypto[i, "name"]. You need to know about the difference between row and column references. The second loop over j is also something that I cannot figure out. Two loops over rows do not seem correct.

CodePudding user response:

What you are looking for:

sapply(crypto$name, function(x)sum(strtoi(charToRaw(x), '16')))
  •  Tags:  
  • r
  • Related