在R中的多级列表上删除data.frames中列的属性 [英] Removing attributes of columns in data.frames on multilevel lists in R

查看:83
本文介绍了在R中的多级列表上删除data.frames中列的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I remove the attributes of the following columns of data.frames on a nested list in R on the fly?

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"

推荐答案

在此线程上回答这个问题可能为时已晚,但我想与大家分享.

This is perhaps too late to answer on this thread, but I wanted to share.

两种解决方案: 1.从merTools包中获取功能stripAttributes.

Two solutions : 1. function stripAttributes from merTools package.

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

  1. to remove the attribute ATT from variable VAR in your data-frame MyData:

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

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

If you want to remove several attributes of all variables :

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

我希望这会有所帮助, 问候

I hope This Helps, Regards

这篇关于在R中的多级列表上删除data.frames中列的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆