My data looks like this:
df<-data.frame(
hhid = c(5668,5595,4724,4756,4856,4730,4757,6320,4758,6319,6311,5477,6322),
pid=c(93660,93660,100960,100960,100960,100960,100960,100962,100960,100962,100962,93814,100962),
pname=c("AB","HG","DC","DC","DC","DC","DC","BA","DC","BA","BA","BH","BA"),
vid=c(462962,608757,772284,772284,772284,293475,293475,656323,293475,656323,81533,465612,656323),
vname=c("ABCD","KJUI","HIND","HIND","HIND","KAJA","KAJA","ADAR","KAJA","ADAR","SANG","NARI","ADAR"),
me=c(1,1,0,0,0,0,0,1,0,0,0,1,0),
ls=c(0,0,1,1,0,1,0,0,1,0,0,0,1),
lg=c(0,0,0,0,0,0,1,0,0,1,0,0,0),
lo=c(0,0,0,0,1,0,0,0,0,0,1,0,0),
amt=c(20000,20000,14000,14000,14000,14000,14000,27000,14000,27000,27000,20000,23000))
There are more than 20000 rows in this data. hhid,pid,pname,vid,vname,ls,lg,lo,amt are column names. Every hhid is unique.
The output that i need is this:
hhid pid pname vid vname LOS amt
5668 93660 AB 462962 ABCD me 20000
5595 93660 HG 608757 KJUI me 20000
4724 100960 DC 772284 HIND ls 14000
4756 100960 DC 772284 HIND ls 14000
4856 100960 DC 772284 HIND lo 14000
and so on.
So basically what i want is replacing 1 in me , ls ,lg , lo columns with a NEW COLUMN LOS which contains column name me, ls, lg, lo as the new row data.That is replacing 1s with Column names and saving that to a new column LOS.