gpt4 book ai didi

r - 删除R中多级列表上data.frames中列的属性

转载 作者:行者123 更新时间:2023-12-04 00:38:08 25 4
gpt4 key购买 nike

如何动态删除R中嵌套列表上data.frames的以下列的属性?

List of 1
$ 0021400001:List of 19
$ GameSummary :'data.frame': 1 obs. of 13 variables:
$ GAME_DATE_EST : Factor w/ 1 level "2014-11-09T00:00:00": 1
- attr(*, "names")= chr "1"
$ GAME_SEQUENCE : Factor w/ 1 level "2": 1
- attr(*, "names")= chr "2"
$ GAME_ID : Factor w/ 1 level "0021400091": 1
- attr(*, "names")= chr "3"
$ GAME_STATUS_ID : Factor w/ 1 level "3": 1
- attr(*, "names")= chr "4"
$ SeasonSeries :'data.frame': 1 obs. of 7 variables:
$ GAME_ID : Factor w/ 1 level "0021400001": 1
- attr(*, "names")= chr "1"
$ HOME_TEAM_ID : Factor w/ 1 level "1610612740": 1
- attr(*, "names")= chr "2"
$ VISITOR_TEAM_ID : Factor w/ 1 level "1610612753": 1
- attr(*, "names")= chr "3"

最佳答案

在这个线程上回答这个问题可能为时已晚,但我想分享一下。

两种解决方案:
1.来自merTools包的功能stripAttributes。


从数据框MyData中的变量VAR中删除属性ATT:

attr(MyData$VAR, "ATT") <- NULL



如果要删除所有变量的几个属性:

For (var in colnames(MyData)) {
attr(MyData[,deparse(as.name(var))], "ATT_1") <- NULL
attr(MyData[,deparse(as.name(var))], "ATT_2") <- NULL
}


我希望这有帮助,
问候

关于r - 删除R中多级列表上data.frames中列的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28873323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com