在解析列名称中的信息并使用它从特定列中收集信息时,重塑R中的表

问题描述

我给了我这个组织不好的数据表,其中有数百列(子集在下面给出)

列名以点分隔,其中第一个字段包含有关对象类型(例如Item123,object_AB等)的信息,而没有任何命名约定。这些列也没有特定的顺序。 其他列共享对象字段的类型,并且还具有该对象的某些属性的名称(例如颜色,制造商等)。

Item123.type.value  Item123.mass.value  Item123.color.value object_AB.type.value  object_AB.mass.value  object_AB.color.value
Desk  11.2  blue  Chair 2.3 orange
Desk 14.2 red Sofa  22  grey
Armchair  23.3  black  Monitor 2.2 white

编辑:添加dput()结构:

structure(list(Item123.type.value = structure(c(2L,2L,1L),levels = c("Armchair","Desk"),class = "factor"),Item123.mass.value = structure(1:3,levels = c("11.2","14.2","23.3"),Item123.color.value = structure(c(2L,3L,levels = c("black","blue","red"),object_AB.type.value = structure(c(1L,2L),levels = c("Chair","Monitor","Sofa"),object_AB.mass.value = structure(c(2L,levels = c("2.2","2.3","22"),object_AB.color.value = structure(c(2L,1L,3L),levels = c("grey","orange","white"),class = "factor")),row.names = c(NA_integer_,-3L),class = "data.frame")

我需要将表转换成这样(行的顺序无关紧要):

type  name  mass  color
Item123  Desk  11.2  blue
Item123  Desk  14.2  red
object_AB  Chair 2.3 orange
object_AB  Sofa  22  grey
Item123  Armchair  23.3  black
object_AB  Monitor 2.2 white

我将非常感谢我能获得的任何帮助!

解决方法

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

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

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