Say I have a data frame like below:
df <- data.frame(x1=c(1,0,0,0),x2=c(0,1,0,0),x3=c(0,0,0,1),x4=c(0,0,1,0))
How can I make a new column with the title name based on if the certain row is equal to 1? So the new data frame would look like:
df2 <- data.frame(x1=c(1,0,0,0),x2=c(0,1,0,0),x3=c(0,0,0,1),x4=c(0,0,1,0),name=c(x1,x2,x4,x3))