[R] Variable which has the maximum value of DF
Hi, Suppose I have a data.frame like this Lines - var1 var2 var3 var4 var5 var6 0 2 1 2 0 0 2 3 7 6 0 1 1.54 9 9 6 0 1.06 1022 3 3 DF - read.table(textConnection(Lines), skip=1) names(DF) - scan(textConnection(Lines), what = , nlines = 1) How do I find the name of the variable which has the maximum value of the data.frame? In this example the answer is var3 (22). Best regards, Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Variable which has the maximum value of DF
Perhaps, names(which.max(sapply(DF, max))) On 15/10/2007, Lauri Nikkinen [EMAIL PROTECTED] wrote: Hi, Suppose I have a data.frame like this Lines - var1 var2 var3 var4 var5 var6 0 2 1 2 0 0 2 3 7 6 0 1 1.54 9 9 6 0 1.06 1022 3 3 DF - read.table(textConnection(Lines), skip=1) names(DF) - scan(textConnection(Lines), what = , nlines = 1) How do I find the name of the variable which has the maximum value of the data.frame? In this example the answer is var3 (22). Best regards, Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Variable which has the maximum value of DF
Henrique Dallazuanna wrote: Perhaps, names(which.max(sapply(DF, max))) Nice. I was thinking along the lines of M - as.matrix(DF) colnames(M)[col(M)[which.max(M)]] On 15/10/2007, Lauri Nikkinen [EMAIL PROTECTED] wrote: Hi, Suppose I have a data.frame like this Lines - var1 var2 var3 var4 var5 var6 0 2 1 2 0 0 2 3 7 6 0 1 1.54 9 9 6 0 1.06 1022 3 3 DF - read.table(textConnection(Lines), skip=1) names(DF) - scan(textConnection(Lines), what = , nlines = 1) How do I find the name of the variable which has the maximum value of the data.frame? In this example the answer is var3 (22). Best regards, Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.