Re: [R] Computing means of multiple variables based on a condition

2016-05-26 Thread Thierry Onkelinx
Another option would be to convert the data into a long format and add columns for each condition. library(dplyr) library(tidyr) DF %>% gather(key = "key", value = "value", -a, -d) %>% mutate( "d>=2" = ifelse(d >= 2, value, NA), "d>=4" = ifelse(d >= 4, value, NA), "d>=6" = ifelse(d

Re: [R] Computing means of multiple variables based on a condition

2016-05-25 Thread Jeff Newmiller
Thank you for including some sample data, but I have to ask that you please invest some time in learning how to edit your code in a text editor and to post in plain text. The quote marks in your example were "curly", which R does not understand. There are other ways in which HTML email leads to

Re: [R] Computing means of multiple variables based on a condition

2016-05-25 Thread KMNanus
These will be overlapping subgroups from the same data frame. For example, d<=2 will have length=9, d<=4 will have length=7, etc. Ken kmna...@gmail.com 914-450-0816 (tel) 347-730-4813 (fax) > On May 25, 2016, at 9:06 PM, William Dunlap wrote: > > Just to be clear, do you really want your '

Re: [R] Computing means of multiple variables based on a condition

2016-05-25 Thread William Dunlap via R-help
Just to be clear, do you really want your 'condition' groups to be be subsets of one another? Most (all?) of the *ply functions assume you want non-overlapping groups so they do a split-summarize-combine sequence. You would have to replace the split part of that. Bill Dunlap TIBCO Software wdunla

[R] Computing means of multiple variables based on a condition

2016-05-25 Thread KMNanus
I have a large dataset, a sample of which is: a<- c(“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”) b <-c(15, 35, 20, 99, 75, 64, 33, 78, 45, 20) c<- c( 111, 234, 456, 876, 246, 662, 345, 480, 512, 179) d<- c(1.1, 3.2, 14.2, 8.7, 12.5, 5.9, 8.3, 6.0, 2.9, 9.3) df <- data.frame(a,b,c,d) I’m tryin