Create a numeric vector with names in one statement?

前端 未结 6 1933
无人及你
无人及你 2020-12-01 09:52

I\'m trying to set the default value for a function parameter to a named numeric. Is there a way to create one in a single statement? I checked ?numeric and ?vector but it

6条回答
  •  盖世英雄少女心
    2020-12-01 10:36

    ...as a side note, the structure function allows you to set ALL attributes, not just names:

    structure(1:10, names=letters[1:10], foo="bar", class="myclass")
    

    Which would produce

     a  b  c  d  e  f  g  h  i  j 
     1  2  3  4  5  6  7  8  9 10 
    attr(,"foo")
    [1] "bar"
    attr(,"class")
    [1] "myclass"
    

提交回复
热议问题