简体   繁体   English

R:将名称添加到列表项

[英]R: Adding a name to a list item

In R, suppose I have defined the following list: 在R中,假设我定义了以下列表:

h <- list(rnorm(3),b="other things")

Now I would like to add the name a to the first item in the list, that is, to change the list h st it becomes h <- list(a=rnorm(3),b="other things") where the instance of rnorm(3) stays the same. 现在,我想将名称a添加到列表中的第一项,即更改列表h st,它将变为h <- list(a=rnorm(3),b="other things")rnorm(3)保持不变。 What is the proper way to do this? 正确的方法是什么?

names(h)[1] <- "a"

由于大卫·阿伦堡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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