如何从R的数据框中的重复行中排他地添加一些值?

问题描述

我有一个包含3个变量(剖面,年龄组和人口)和3011个观测值的数据框。

age_group中有12个不同的年龄段,每个年龄段的编号从1到12。1是18岁的人,2是19岁的人,3是20-24岁的人,4是25岁的人。 -29 ...而12代表65岁以上。

每个部分都有12行,人口按年龄组排序。

我想按世代显示每个部分(z,千禧一代,x,婴儿潮),这将适用于z = age_groups 1:3,millennial = age_groups 4:6,x = age_groups 7:9,boomers = 10 :12

我尝试使用dplyr软件包,特别是ddply,即

    def load_files_to_es(self,files_to_load):
        count = 0
        for file in files_to_load:
            if file.endswith(".jsonl"):
                with open(os.path.join("../pdl_out",file)) as clean_data_file:
                    try:
                        clean_data = json.load(clean_data_file)
                        count += 1
                    except Exception as e:
                        logging.error(f"{e} error processing {file}")
                    else:
                        logging.info("loading data to ES")
                        les.load_pdl_to_es(clean_data=clean_data,filename=file)
                    finally:
                        print(f"Prev File: {file}")
                        if count % 10 == 0:
                            gc.collect()

但是idk如何在不将所有年龄段合并在一起的情况下与每个组分开。

fragment of the table I'm using

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)