相关文章推荐
博学的绿茶  ·  使用Resource Hacker ...·  2 月前    · 
博学的绿茶  ·  Utility Types | Vue.js·  10 月前    · 
博学的绿茶  ·  Help And Training ...·  11 月前    · 
博学的绿茶  ·  r - Caused by error ...·  1 年前    · 
独立的眼镜  ·  如何连接Babelfish for RDS ...·  45 分钟前    · 
发财的蛋挞  ·  Microsoft Azure Data ...·  45 分钟前    · 
冷冷的投影仪  ·  Secure an ASP.NET ...·  1小时前    · 
不羁的生姜  ·  PSPSDK 开发的时候出现 ...·  1小时前    · 
儒雅的投影仪  ·  Perl 包和模块 | ·  2 小时前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to generate the following vector without using c() : a1, b2, b3, c4, c4, c6 . I am having a really hard time with this. I tried to make a simple python function to help visualize it:

listy = []
size = 2
lets = ["a", "b", "c"]
iterator = 1
for i in range(1, 4):
    let = lets[i-1]
    for j in range(3-size):
        listy.append(let + str(iterator))
        iterator += 1
    size -= 1
print(listy)

But I can't get anything similar to work in R. I would greatly appreciate some help. About the closest I've gotten is this:

paste(rep(1:6), rep(letters[1:3]))

But obviously that's way off. Am I going to have to use for loops to generate this? It seems like there must be a simpler way... I am new to vector generation and the functions don't seem intuitive at all. If you could just give a poke in the right direction I'm sure I could figure it out. Thanks!

tmp <- rep(vec, seq_along(vec)) paste0(tmp, seq_along(tmp)) #[1] "a1" "b2" "b3" "c4" "c5" "c6"

By hardcoding this is similar to :

paste0(rep(c('a', 'b', 'c'), 1:3), 1:6)
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章