0

This is my dataframe in r studio. I'm trying to find code what will produce the name of the student with he highest age.

students.df #Name of dataframe
  name DAD BDA gender nationality age
1  Amy  80  70      F         IRL  20
2 Bill  65  50      M          UK  21
3 Carl  50  80      M         IRL  22
Sotos
  • 51,121
  • 6
  • 32
  • 66
FizWidget
  • 11
  • 3

2 Answers2

1

as.character(subset(students.df,students.df$age==max(students.df$age))$name)

library(dplyr)

students.df %>% filter(age==max(age)) %>% select(name)

Daman deep
  • 631
  • 3
  • 14
0

you can try this

students.df[which.max(student.df$age),]
Kian
  • 110
  • 7
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Nov 19 '20 at 11:52