Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 208627

Creating a vector of numbers based on letters

$
0
0

So, this is the question:

"Create a function that given one word, return the position of word’s letters on letters vector. For example, if the word is ‘abba’, the function will return 1 2 2 1."

What I have so far is this:

l <- function(word) {
    chr <- c()
    y <- c()
    strsplit(chr,word)
    i<-1
    while(i<length) {
           o<-letters[i]
           x<-chr[i]
           if(o==x) {
                    y[i]<-i
           }
           i+1
    }
    y
}

I have tried running l("hello") and it returns NULL. I'm very lost and would appreciate any help! Thank you!


Viewing all articles
Browse latest Browse all 208627

Latest Images

Trending Articles



Latest Images