Re: [R] Generating Patient Data

2014-07-01 Thread David Winsemius
On Jun 25, 2014, at 1:49 PM, David Winsemius wrote: > > On Jun 24, 2014, at 11:18 PM, Abhinaba Roy wrote: > >> Hi David, >> >> I was thinking something like this: >> >> ID Disease >> 1 A >> 2 B >> 3 A >> 1C >> 2D >> 5A >> 4B >> 3D >> 2A >> .... >> >>

Re: [R] Generating Patient Data

2014-06-25 Thread David Winsemius
On Jun 24, 2014, at 11:18 PM, Abhinaba Roy wrote: > Hi David, > > I was thinking something like this: > > ID Disease > 1 A > 2 B > 3 A > 1C > 2D > 5A > 4B > 3D > 2A > .... > > How can this be done? do.call(rbind, lapply( 1:20, function(pt) {

Re: [R] Generating Patient Data

2014-06-25 Thread arun
Also, you can do: library(dplyr) dat%>%group_by(ID)%>%filter(length(unique(Disease))>1)%>%arrange(Disease,ID) A.K. On Wednesday, June 25, 2014 3:45 AM, arun wrote: Forgot about: library(reshape2) On , arun wrote: Hi, Check if this works:  set.seed(495)  dat <- data.frame(ID=sample

Re: [R] Generating Patient Data

2014-06-25 Thread arun
Hi, Check if this works:  set.seed(495)  dat <- data.frame(ID=sample(1:10,20,replace=TRUE), Disease=sample(LETTERS[1:6], 20, replace=TRUE) ) subset(melt(table(dat)[rowSums(!!table(dat))>1,]), !!value,select=1:2)    ID Disease 1   2   A 3   4   A 4   6   A 6  10   A 8   3  

Re: [R] Generating Patient Data

2014-06-25 Thread Anthony Damico
# build off of david's suggestion x <- data.frame( patient= 1:20 , disease = sapply( pmin( 2 + rpois( 20 , 2 ) , 6 ) , function( n ) paste0( sample( c('A','B','C','D','E','F'), n), collapse="+" ) ) ) # break the diseas

Re: [R] Generating Patient Data

2014-06-24 Thread Abhinaba Roy
Hi David, I was thinking something like this: ID Disease 1 A 2 B 3 A 1C 2D 5A 4B 3D 2A .... How can this be done? On Wed, Jun 25, 2014 at 11:34 AM, David Winsemius wrote: > > On Jun 24, 2014, at 10:14 PM, Abhinaba Roy wrote: > > > Dear R helpers, > >

Re: [R] Generating Patient Data

2014-06-24 Thread David Winsemius
On Jun 24, 2014, at 10:14 PM, Abhinaba Roy wrote: > Dear R helpers, > > I want to generate data for say 1000 patients (i.e., 1000 unique IDs) > having suffered from various diseases in the past (say diseases > A,B,C,D,E,F). The only condition imposed is that each patient should've > suffered fro

[R] Generating Patient Data

2014-06-24 Thread Abhinaba Roy
Dear R helpers, I want to generate data for say 1000 patients (i.e., 1000 unique IDs) having suffered from various diseases in the past (say diseases A,B,C,D,E,F). The only condition imposed is that each patient should've suffered from *atleast* two diseases. So my data frame will have two columns