Re: [R] Accessing the index of factor in by() function

2011-08-01 Thread Sarah Goslee
Merik, You did get an answer to the question, and it's even included in the material below. What doesn't work for you in Ista's suggestion? id<- c(1,1,1,1,1,2,2,2,3,3,3) month <- c(1, 1, 2, 3, 6, 2, 3, 6, 1, 3, 5) value <- c(10, 12, 11, 14, 16, 12, 10, 8, 14, 11, 15) dat.tmp <- data.frame(id

Re: [R] Accessing the index of factor in by() function

2011-08-01 Thread Merik Nanish
Since I didn't get an answer to this question, I'm rephrasing my question in simpler terms: I have a dataframe and I want to split it based on the levels of one of its columns, and apply a function to each section of the data. Output of the function may be drawing a plot, returning a value, what

Re: [R] Accessing the index of factor in by() function

2011-07-27 Thread Merik Nanish
On Tue, Jul 26, 2011 at 10:12 AM, Ista Zahn wrote: > OK, easy enough: > > dat.tmp <- data.frame(id, month, value) > my.plot <- function(dat) {print(dat[, c("id", "value")])} > by(dat.tmp, id, my.plot) Excellent. The output of that last line is: * id value 1 110 2 112 3 111 4 1

Re: [R] Accessing the index of factor in by() function

2011-07-26 Thread Ista Zahn
Hi Merik, Please keep the mailing list copied. On Tue, Jul 26, 2011 at 6:44 AM, Merik Nanish wrote: > You can convert my data into a dataframe simply by dat <- data.frame(id, > month, value). That doesn't help though. Can you be more specific? What is the problem you are having? And no, that's

Re: [R] Accessing the index of factor in by() function

2011-07-25 Thread Ista Zahn
Hi Merik, by() works most easily with data.frames. Is this what you are after? my.plot <- function(dat) { print(dat$value); print(dat$month[dat$id==dat$value]) } by(dat.tmp, id, my.plot) Best, Ista On Mon, Jul 25, 2011 at 9:19 PM, Merik Nanish wrote: > Hello, > > Here are three vectors to give

[R] Accessing the index of factor in by() function

2011-07-25 Thread Merik Nanish
Hello, Here are three vectors to give context to my question below: *id<- c(1,1,1,1,1,2,2,2,3,3,3)) month <- c(1, 1, 2, 3, 6, 2, 3, 6, 1, 3, 5) value <- c(10, 12, 11, 14, 16, 12, 10, 8, 14, 11, 15)* and I want to plot "value" over "month" separately for each "id". Before I can do that, I nee