combinations - If multiple condition not giving output in r -
i have dataframe
df= data.frame(id=paste(rep("a",7),c(1:7),sep = ""), col2=c(12,10,1,2,5,10,8), col3=c(200,150,180,450,100,130,200))
i'm trying check combination of element sum upto particular number , same elements checking sumproduct not giving output e.g dataframe df these values make sum of 25, so
col2 col3 10 150 5 100 10 130 =sumproduct((e3:e5,d3:d5) [excel formula] output = 3300
and expect output following code a2,a5,a6
this code
for(i in 1:nrow(df)){ comb <- combn(1:nrow(df), i, fun = null, simplify = true) (j in 1:ncol(comb)){ subvec <- comb[,j] <- sum(df[subvec,2]) b <- sum(df[i, 2] * df[i, 3]) if(a == 25 && b == 3300){ print(df[subvec,1]) } } }
Comments
Post a Comment