Re: [R] Sorting Dataframes

2011-06-12 Thread SamiC
Thanks very much. I did it using the do.call and compared it to my loop method and the results were exactly the same. In future i think i will use this function - a lot less typing and time consuming! -- View this message in context: http://r.789695.n4.nabble.com/Sorting-Dataframes-tp3580075p

Re: [R] Sorting Dataframes

2011-06-07 Thread Dennis Murphy
Hi: Here's another approach using the plyr package: # Write a function that takes a data frame as input and outputs a data frame f <- function(df) df[which.max(df$Fish), ] ddply(x, 'Bin', f) Bin Depth Fish 1 1 8 24 2 2 8 21 3 312 33 HTH, Dennis On Tue, Jun 7, 2011 at 3

Re: [R] Sorting DataFrames

2011-06-07 Thread Ethan Brown
Hello Samantha, I'm having some trouble understanding your question in terms of what's happening in R. Are these "bins" columns of a data.frame? Rows? It's helpful for us to have a small example to look at--for instance, you could create a small subset of your data called x, then type the command

Re: [R] Sorting Dataframes

2011-06-07 Thread David A. Johnston
Here's one way: # Here I read in your data to a variable 'x' x = read.delim(textConnection( "Bin Depth Fish 1 4 2 1 8 24 1 12 4 2 4 3 2 8 21 2 12 2 3 4 12 3 8 2 3 12 33"), sep = " ", header = TRUE) do.call(rbind, lapply(split(x, x$Bin), function(grp) grp[which.max(grp$Fish),])) -- View this mes

Re: [R] Sorting Dataframes

2011-06-07 Thread SamiC
So I have figured out how to do it via a series of loops and conditions, but i am thinking there must be a quicker way to do it. an example. Bin Depth Fish to: Bin DepthMaxFish 1 4 2 1 8 24 1 8

[R] Sorting Dataframes

2011-06-07 Thread SamiC
I am a new user, and i am trying to sort out a data frame. I have for example bins of data. Within each bin i have multiple counts of animals and the depths at which these count were taken. How would I summarise this to being only the maximum count per bin alongisde the corresponding height (but

Re: [R] Sorting Dataframes

2011-06-07 Thread David Winsemius
SamiC wrote: > > I am a new user, and i am trying to sort out a data frame. > > I have for example bins of data. Within each bin i have multiple counts > of animals and the depths at which these count were taken. How would I > summarise this to being only the maximum count per bin alongisde th

[R] Sorting DataFrames

2011-06-07 Thread Cox, Samantha Lucy
I am a new user, and i am trying to sort out a data frame. I have for example bins of data. Within each bin i have multiple counts of animals and the depths at which these count were taken. How would I summarise this to being only the maximum count per bin alongisde the corresponding height