I have following data frame: Little history about the data and frame. This is the second version initial data frame has actual similarity values that they represent based on the column titles. Based on the actual similarity values, each has been identified by the bin that they belong to and I consider bin is actual score.
cosinFcolor cosinEdge cosinTexture histoFcolor histoEdge histoTexture jaccard
1 3 0 0 1 1 0 0
2 0 0 5 0 2 2 0
3 1 0 2 0 0 1 0
4 0 0 3 0 1 1 0
5 1 3 1 0 4 0 0
6 0 0 1 0 0 0 0
What I want to do is sum each row value and and save it in a column next to jaccard column but during the summation I want to check the value of jaccard and here is the sudo code of what I want to do based on jaccard value:
This is the SUDO CODE:
If jaccard.value of that row == 5
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .5)
If jaccard.value of that row == 4
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .4)
If jaccard.value of that row == 3
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture)+= (jaccard.value of the row * .3)
If jaccard.value of that row == 2
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .2)
If jaccard.value of that row == 1
(cosinFcolor + cosinEdge + cosinTexture + histoFcolor + histoEdge + histoTexture) += (jaccard.value of the row * .1)
else if jaccard.value of that row == 0
value in the new column is = -1
Once this operation is done, I am hoping to have final data frame as shown below:
cosinFcolor cosinEdge cosinTexture histoFcolor histoEdge histoTexture jaccard weightedScore
1 3 0 0 1 1 0 0 -1
2 0 0 5 0 2 2 0 -1
3 1 0 2 0 0 1 0 -1
4 0 0 3 0 1 1 0 -1
5 1 3 1 0 4 0 0 -1
6 0 0 1 0 0 0 0 -1
7 0 0 1 0 0 0 1 1.1
My initial (First Data frame, that I hav put) was generated by following R code with the help StackOverflow user:
Here is the R-Code:
single_img_sim_no_title <- single_img_similarity
single_img_sim_no_title$title <- NULL
head(single_img_sim_no_title)
#converting it to bins
sing_img_bins <- apply(single_img_sim_no_title, 2, cut, c(-Inf, seq(0.5, 1, 0.1), Inf), labels=0:6)
sing_img_bins[sing_img_bins=="6"] <- "0"
sing_img_bins <- as.data.frame(sing_img_bins)