I am attempting to merge all columns with different names but identical variable labels (imported from an SPSS file). The way I am trying to go about this is running a few checks to make sure the columns are neither NA
nor identical, then pasting j
to i
and deleting j
. However, this appears to be changing nothing whatsoever in my dataframe. What am I doing wrong here?
A note-- mergedSet is rows bound together from set1 and set2, each of which contain the labels.
for(i in colnames(set1)) {
for(j in colnames(set2)){
if(!is.na(attributes(set1)$variable.labels[i]) &&
!is.na(attributes(set2)$variable.labels[j])) {
if(attributes(set1)$variable.labels[i] ==
attributes(set2)$variable.labels[j]) {
if(i != j) {
mergedSet <- within(mergedSet, i <- paste(i,j))
mergedSet <- within(mergedSet, rm(j))
}
}
}
}
}