Hi Srini,
This may be as simple as tapply(weight,fruit,max)
or t(that) if you want it as you specified.
--Adam
On Sun, 7 Sep 2008, Srinivas Iyyer wrote:
dear group,
i have a data matrix with some replicate items with different values. I want to
extract the row with max value.
for example:
TED] [mailto:[EMAIL PROTECTED] On Behalf Of Srinivas Iyyer
Sent: Monday, September 08, 2008 7:55 AM
To: [EMAIL PROTECTED]
Subject: [R] extracting max row from data matrix
dear group,
i have a data matrix with some replicate items with different values. I want to
extract the row with max value.
Dear Srini,
Here is one way:
# Data set
x=read.table(textConnection("fruit weight
1 apple1.3
2 apple1.5
3 apple1.6
4 orange1.4
5 orange1.6"),header=TRUE)
x[tapply(x$weight,x$fruit,which.max),]
apple orange
1.61.6
or
Try also
x[cumsum(tapply(x$weight,x$fruit,whic
dear group,
i have a data matrix with some replicate items with different values. I want to
extract the row with max value.
for example:
> x
fruit weight
1 apple1.3
2 apple1.5
3 apple1.6
4 orange1.4
5 orange1.6
x is a data frame.
I want to extract unique items from
4 matches
Mail list logo