I find quite strange the confusion that has been made in the field of attributes/tags/labels or whatever it has been called to columns in dataframe.
The question is very easy: I have a dataframe (let's call it StackedDataStd) with cases (rows) and variables (columns). Each column have a name and you can access it through many of different ways (imho having 10 ways to make the same task make everything more confused...)
colnames(stackedDataStd)
names(stackedDataStd)
labels(stackedDataStd)2
attr(stackedDataStd,'names')
attributes(stackedDataStd)$names
[1] "segN" "patN" "Elongation" "Flatness" "LeastAxisLength" [6] "MajorAxisLength" "Maximum2DDiameterColumn" "Maximum2DDiameterRow" "Maximum2DDiameterSlice" "Maximum3DDiameter" [11] "MeshVolume" "MinorAxisLength" "Sphericity" "SurfaceArea" "SurfaceVolumeRatio" [16] "VoxelVolume"
when I remove a column the corresponding name is removed from the attributes.
Now I have many other tags to identify the types of used variables...let's make the example of bw tag (an integer number, in my case 1,2,4,8 or 16). Each column has his own bw and what I want is to select, let's say, all the columns with bw==1.
At the moment I made what I called a selector (selectorBw): a vector of length dim(stackedDataStd)2 with the bw values of each column.
By using stackedDataStd[,selectorBw == 1] I select the ones with bw==1.
But, every time I remove a column I have to remember to remove the corresponding position in the selector (and having ten selectors it start being a mess).
stackedDataStd[,-4]
selectorBw[-4]
I tried to add attributes in several ways:
attr(stackedDataStd,'bw') <- selectorBw
adds the attribute but it's not linked to the column like colnames. If I remove one column (stackedDataStd$segN <- c()) the attribute is not removed. If I remove with stackedDataStd <- stackedDataStd[,-1] the attribute disappears... (magic).
Here it has been suggested to assign the attribute to each element of the list:
for (i in seq_along(stackedDataStd)) { attr(stackedDataStd[[i]], "bw") <- selectorBw[i] }
but it can't be used with the whole dataframe, since it's not a dataframe attribute (i should cycle for each variable for every selection).
I have tried other ways, but i don't want to bother you with my attempts....
Do you have any suggestion? Maybe with Hmisc package? I don't want to have non-standard dataframe, if possibile.
bw == 1
– starja