I have data like this:
example_df <- data.frame(
col1type1 =c(110:106),
col2type2 = c(-108:-104),
col3type1 = c(-109:-105),
col4type2 =c(110:106),
col5type1 =c(107:103),
col6type2 = c(-110:-106),
col7type1 =c(109:113),
col8type2 = c(-120:-116),
col9type1 = c(-105:-101),
col10type2 =c(105:101),
col11type1 = c(-125:-121),
col12type2 = c(-105:-101)
)
I want to return only combinations where type1+type2>=0 on the same row and return to a new df the combination where it was >=0, the row, and the two numbers: (I know I could use for/foreach to calculate each cell individually and output to a data.frame, but there has to be a more efficient way)
Desired output like this (incomplete):
#for all possible combinations, like the example rows below
example_first <- data.frame(column_combination="col1type1_col2type2", row=1, sum=2,col1number=110,col2number=-108)
example_mid<- data.frame(column_combination="col1type1_col12type2",row=3, sum=5,col1number=108,col2number=-103)
example_last <- data.frame(column_combination="col9type1_col10type2",row=5,sum=0,col1number=-101,col2number=101)
#would want like this for all possible combinations
desired_incomplete_output <- rbind(example_first,example_mid,example_last)
What is an efficient way to calculate this en masse rather than a brutal for/foreach loop? Thanks!