[R] How to find values that correspond to a given value (i.e. max)
arun
smartpink111 at yahoo.com
Wed Sep 18 22:00:55 CEST 2013
Hi,
Try:
all[which.max(all$income),c('names','age')]
# names age
#2 Jim 25
A.K.
Hi everyone
I'm new to R, so this is probably a stupid question, but I looked
around for quite a while an couldn't find an answer. Basically I'm
trying to print values that correspond to a found maximum.
If I have this:
"names" <- c("John", "Jim", "Mary", "Susan")
"age" <- c(16, 25, 32, 56)
"income" <- c(2000, 3000, 2500, 1500)
"all"<- data.frame(names, age, income)
max(all$income)
I would like to print the name and age that correspond to the
found maximum. I tried some if-statements, but they didn't work because
my programming skills outside of SQL are basically non-existent.
I'd be glad for any pointers, thanks
More information about the R-help
mailing list