[R] Generating Patient Data

arun smartpink111 at yahoo.com
Wed Jun 25 09:50:03 CEST 2014


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 <smartpink111 at yahoo.com> wrote:


Forgot about:
library(reshape2)





On , arun <smartpink111 at yahoo.com> wrote:



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       B
15  4       C
16  6       C
20  3       D
22  6       D
24 10       D
26  3       E
27  4       E
29  7       E
31  2       F
33  4       F
35  7       F
A.K.






On Wednesday, June 25, 2014 1:17 AM, Abhinaba Roy <abhinabaroy09 at gmail.com> 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 from *atleast* two diseases. So my data frame will have two
columns 'ID' and 'Disease'.

I want to do a basket analysis with this data, where ID will be the
identifier and we will establish rules based on the 'Disease' column.

How can I generate this type of data in R?

-- 
Regards
Abhinaba Roy

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list