简体   繁体   中英

R Debugging Issue - Code not working

Hi Im having issues with the following code:

RepLetter(n) <- function(){
    return(rep(letters[7]))
}

I want to create a function that returns the nth letter of the alphabet n times.

For example I would want "c" repeated like "c", "c", "c"

So I could type RepLetter(5) and R would return "e", "e", "e", "e", "e"

You have your function argument in the wrong place, and your arguments to rep are off.

Try this: 

RepLetter <- function(n){
  return(rep(letters[n],n))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM