# Finding coordinates for maximum of a function Classic List Threaded 7 messages Open this post in threaded view
|

## Finding coordinates for maximum of a function

 Hello R, I have data in txt file of n columns like this: x  y1 .....yn 1  100 2  50 3  10 4  200 5  20 I need to find coordinates for each maxima e.g.: [x,y1],[x,y2]...[x,yn] a=read.table() attach(a) b=y1<-x max(b) returns only value of y but no corresponding x value
Open this post in threaded view
|

## Re: Finding coordinates for maximum of a function

 This is where which.max() comes in handy. Let Y be a matrix of all of column vectors of y n<-length(x) x.c<-rep(0,n) for(i in 1:n){ x.c[i]<-which.max(Y[,i]) } x.c is then a vector of x coordinates for the maximum for columns y1,y2,...,yn
Open this post in threaded view
|

## Re: Finding coordinates for maximum of a function

 This post was updated on . CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## Re: Finding coordinates for maximum of a function

 It occured to me: x[max(y)] simple isn't it?
Open this post in threaded view
|

## Re: Finding coordinates for maximum of a function

 That actually won't work.  max(y) will give a value, not a coordinate, so x[max(y)] is definitely not what you want.