重命名列表项

编程入门 行业动态 更新时间:2024-10-25 01:21:54
本文介绍了重命名列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下列表listaValores

listaValores <- c() for(valores in 1:numRepeticion){ listaValores <- c(listaValores, readWorksheetFromFile(file = file.read, sheet = sheet.read, startRow = startRow.read+(12*(valores-1)), startCol = startCol.read[i], endRow = startRow.read+((12*valores)-1) , endCol = startCol.read[i], header = FALSE)) }

返回:

$Col1 [1] 32824 35646 34650 29328 27376 28548 35363 34740 49181 57960 55550 50626 $Col1 [1] 52610 55085 58576 51300 50968 58104 56585 38273 54216 59043 67487 58067 $Col1 [1] 59142 68593 77510 73434 83545 83483 79635 69269 85703 73080

如何将其元素重命名为2014,2015,2016?

How to renames it's elements to 2014, 2015, 2016?

推荐答案

请注意,您有list.因此,您没有colnames,而是names.您可以像这样编辑它们:

Note that you have a list. Therefore, you do not have colnames but names. You can edit them like this:

l <- list(col1 = c(123123, 12123, 123123), col1 = c(123123, 12123, 123123)) l # $col1 # [1] 123123 12123 123123 # # $col1 # [1] 123123 12123 123123 names(l) # [1] "col1" "col1" names(l) <- c("2014", "2015") l # $`2014` # [1] 123123 12123 123123 # # $`2015` # [1] 123123 12123 123123

要仅编辑列表中的某些条目,请指定索引:

To only edit certain entries in the list, specify an index:

names(l)[1] <- "new_name" l # $`new_name` # [1] 123123 12123 123123 # # $`2015` # [1] 123123 12123 123123

如果您想进一步了解R中的不同数据类型,我可以推荐哈德利·威克姆(Hadley Wickham)的摘要.

If you'd like to know more about the different data types in R, I can recommend Hadley Wickham's summary.

更多推荐

重命名列表项

本文发布于:2023-10-16 16:04:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重命名   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!