I have a data set with each column having an attribute storing data. Meaning, columns has row wise values and then attributes to columns also have a value.
I can read the data attached to the column as attribute using attr()
. However, my goal is to capture these attribute values and replicate as a columns.
Reading Attribute
> attr(data$`column1`, "metadata")$DP.SomeNumber1
"6200"
> attr(data$`column2`, "metadata")$DP.SomeNumber2
"7200"
Input Data
column1 column2
-0.01 0.05
-0.01 0.05
-0.01 0.05
-0.01 0.05
-0.01 0.05
-0.01 0.05
-0.01 0.05
-0.01 0.05
Then using above code, I want to append the values as shown below.
Output Data
column1 SomeNumber1 column2 SomeNumber2
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
-0.01 6200 0.05 7200
How can I implement this recursively for data with more than 1000 columns? Each read will require call to attr()
with unique column name to capture the attribute data and then replicate it as another adjust column.
I am getting confused on how I can recursively do this and that too in an optimized way.
Please share suggestions, thanks.