Hi all,
I'm stuck trying to get syntax correct for the follwing type of loop. I would like to find the column with the largest value in a given row, and create a new column with a categorical variable indicating which column the highest value of "i" comes from.

too=data.frame(A=rnorm(10,1),B=rnorm(10,2),C=rnorm(10,1.5))
too$large=0
too$large=for (i in 1:length(too[,c(1,2,3)])) {
if (too$A[i] > too$B[i] & too$C[i]) {too$large[i]=1} else if (too$B[i] > too$A[i] & too$C[i]) {too$large[i]=2} else if (too$C[i] > too$A[i] & too$B[i]) {too$large[i]=3}}

Ultiamtely this is not working for me, any hints would be much appreciated!

--
David Depew
PhD Candidate
Department of Biology
University of Waterloo
200 University Ave W
Waterloo, Ontario, Canada
N2L 3G1

T:(1)-519-888-4567 x 33895
F:(1)-519-746-0614

dde...@scimail.uwaterloo.ca
http://www.science.uwaterloo.ca/~ddepew

______________________________________________
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.

Reply via email to