I have a dataframe with 4 colums here is the structure.
I would like to create a new vector (valuetofind) with the value of 1 if all my rows have the number 1 and -1 if all my rows have the number -1.
Otherwhise just fill with NA.
str(results)
'data.frame': 435 obs. of 4 variables:
$ model.knn: Factor w/ 2 levels "-1","1": 2 2 2 2 2 2 2 1 2 2 ...
$ p.arbre : Factor w/ 2 levels "-1","1": 2 2 1 1 2 2 2 1 2 2 ...
$ p.svm : Factor w/ 2 levels "-1","1": 2 2 2 2 2 2 2 2 2 2 ...
$ p.rf : Factor w/ 2 levels "-1","1": 2 2 2 1 2 2 2 1 2 2 ...
model.knn p.arbre p.svm p.rf Valuetofind
1 1 1 1 1
-1 -1 1 1 NA
-1 -1 -1 -1 -1
I have been trying many things but I am blocked
I tried to convert to numeric, the facor in my dataframe. It gave me values of 2 and 1 instread of my -1 and 1.