如何在R中加入标签?

时间:2022-06-08 14:58:39

I am using R currently and I want to know how can I label the list objects when I declare a list. For example: return(list(xhat,alpha,beta)), and xhat, alpha and beta are themselves arrays. I want to give each an appropriate label.

我目前正在使用R,我想知道如何在声明列表时标记列表对象。例如:return(list(xhat,alpha,beta)),而xhat、alpha和beta本身就是数组。我想给每个人一个合适的标签。

Thank you.

谢谢你!

2 个解决方案

#1


21  

For simple cases Michael's answer will work. Sometimes though you have a vector of names my_names which you would like to use to name/rename the output. There are at least three ways:

对于简单的例子,迈克尔的答案是有效的。有时,虽然有一个mynames _names向量,但您希望使用它来命名/重命名输出。至少有三种方法:

  • use names<-:

    使用名称< - - - - - -:

    out <- list(xhat,alpha,beta)  
    names(out) <- my_names  
    out
    
  • use setNames():

    使用setNames():

    setNames(out, my_names)
    
  • use structure():

    利用结构():

    structure(out, names=my_names)
    

#2


7  

All you need is list(x=xhat, a=alpha, b=beta)

你只需要列表(x=xhat, a=alpha, b=beta)

#1


21  

For simple cases Michael's answer will work. Sometimes though you have a vector of names my_names which you would like to use to name/rename the output. There are at least three ways:

对于简单的例子,迈克尔的答案是有效的。有时,虽然有一个mynames _names向量,但您希望使用它来命名/重命名输出。至少有三种方法:

  • use names<-:

    使用名称< - - - - - -:

    out <- list(xhat,alpha,beta)  
    names(out) <- my_names  
    out
    
  • use setNames():

    使用setNames():

    setNames(out, my_names)
    
  • use structure():

    利用结构():

    structure(out, names=my_names)
    

#2


7  

All you need is list(x=xhat, a=alpha, b=beta)

你只需要列表(x=xhat, a=alpha, b=beta)