This is very similar to the post "Replace all values in a column of one dataframe using values in a row of another dataframe (matching by row name and column name)"
Except my replacement requirement is the ones ("1") are replaced by the name of the column the one is in.
The example setup
df1<-data.frame(replicate(5,sample(0:1,5,rep=TRUE)))
row.names(df1)<-c("hootsuite","foodtank","FarmsNews","agchat","TysonFoods")
names(df1)<-c("food","agvocate","editor","gmo","ag")
food agvocate editor gmo ag
hootsuite 1 1 0 0 1
foodtank 1 1 0 0 1
FarmsNews 1 0 1 0 1
agchat 0 0 0 0 1
TysonFoods 1 0 1 1 0
would become
food agvocate editor gmo ag
hootsuite food agvocate 0 0 ag
foodtank food agvocate 0 0 ag
FarmsNews food 0 editor 0 ag
agchat 0 0 0 0 ag
TysonFoods food 0 editor gmo 0
The solutions in the similar post
df1*df2[,1][col(df1)]
or
sweep(df1, 2, df2[,1], "*")
(using df2 as defined below)
df2<-c("food","agvocate","editor","gmo","ag")
df2<-as.matrix(df2)
row.names(df2)<-c("food","agvocate","editor","gmo","ag")
give an error "Error in FUN(left, right) : non-numeric argument to binary operator", meaning the matrix multiplication really is not for characters ;)
So the approach I should take is what?