0

I have a dataframe with 400 people who each have three predicted values (so 400 rows, 3 columns). Now I need a function that writes me the lowest of these three values into a variable, so that every person has the best prediction in a fourth column. I can't find any possibility, so I would be very thankful for your help!

1 Answers1

0

Imagine you had 3 columns named Score1, Score2, and Score3. You might use apply as follows:

data$MinScore <- apply(data[,c("Score1","Score2","Score3")],1,min)
head(data)
   Person Score1 Score2 Score3 MinScore
1 Person1     11     90     73       11
2 Person2     60     85     76       60
3 Person3     20     16     36       16
4 Person4     95     87     66       66
5 Person5     99     81     20       20
6 Person6     42     79     80       42

Sample Data

data <- data.frame(Person = paste0("Person", 1:400),Score1 = sample(1:100,100),Score2 = sample(1:100,100),Score3 = sample(1:100,100))
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57