How do you create a list with a single value in R?

后端 未结 2 639
醉梦人生
醉梦人生 2021-01-17 08:02

How do you create a list with a single value in R? For example, I want a list of 50 zeros.
What is the easiest way to define this?

相关标签:
2条回答
  • 2021-01-17 08:24

    Maybe

    res <- list(rep(0,50))
    

    is all you need?

    0 讨论(0)
  • 2021-01-17 08:30

    How is a list of 50 zeros ~ a list with a single value?

    Try this:

    list(rep(0, 50))
    

    Or if you want a list with fifty separate elements of zeros, you can do this:

    as.list(rep(0, 50))
    
    0 讨论(0)
提交回复
热议问题