matrix - How to create nested data in R - Nest multiple columns in different categories -


my data looks this:

> str(tab2)  'data.frame':	36 obs. of  22 variables:   $ organisationunitname        : factor w/ 38 levels "all ous","angola",..: 2 3 4 5 6 7 8 9 10 11 ...   $ cd4_perform_result          : num  24 6 7 1 1 1 5 3 2 1 ...   $ cd4_participate_result      : num  1 8 8 1 1 1 5 3 2 1 ...   $ cd4_pass_result             : num  1 4 19 1 1 1 5 3 2 1 ...   $ eid_perform_result          : num  2 1 7 1 1 1 1 9 1 1 ...   $ eid_participate_result      : num  2 1 5 1 1 1 1 8 1 1 ...   $ eid_pass_result             : num  2 1 5 1 1 1 1 7 1 1 ...   $ vl_perform_result           : num  2 1 3 1 1 1 1 9 1 1 ...   $ vl_participate_result       : num  2 1 7 1 1 1 1 7 1 1 ...   $ vl_pass_result              : num  2 1 7 1 1 1 1 7 1 1 ...   $ hiv_perform_result          : num  19 29 14 1 1 1 26 21 10 1 ...   $ hiv_participate_result      : num  19 28 14 1 1 1 22 20 4 1 ...   $ hiv_pass_result             : num  20 28 14 1 1 1 18 22 7 1 ...   $ tbafb_perform_result        : num  9 1 8 1 1 1 1 7 1 1 ...   $ tbafb_participate_result    : num  1 1 18 1 1 1 1 5 1 1 ...   $ tbafb_pass_result           : num  1 1 19 1 1 1 1 6 1 1 ...   $ tbculture_perform_result    : num  3 1 2 1 1 1 1 1 1 1 ...   $ tbculture_participate_result: num  1 1 2 1 1 1 1 1 1 1 ...   $ tbculture_pass_result       : num  1 1 1 1 1 1 1 1 1 1 ...   $ tbxpert_perform_result      : num  1 1 4 1 1 1 1 1 1 1 ...   $ tbxpert_participate_result  : num  1 1 5 1 1 1 1 1 1 1 ...   $ tbxpert_pass_result         : num  1 1 2 1 1 1 1 1 1 1 ...  > 

data

structure(list(country = c("erkf", "kjfd", "wjko", "hovb", "v6dm",   "vp8p", "tyhi", "u4ob", "gvnl", "dzjo", "11jx", "ygwc", "4ye1",   "rykq", "ohlw", "xh1x", "mol4", "67vy", "h2ca", "ue1r", "hr9g",   "yxpi", "s0or", "2fss", "wz9f", "xeog", "vptm", "xaup", "stbg",   "aayu", "mjyw", "pvng", "qncq", "l8dk", "6cj8", "90i7"), cd4_perform_result = c(23,   6, 7, 1, 1, 1, 5, 3, 2, 1, 10, 1, 2, 8, 1, 2, 16, 1, 1, 22, 12,   1, 13, 11, 17, 1, 20, 15, 1, 21, 18, 4, 1, 14, 19, 9), cd4_participate_result = c(1,   8, 8, 1, 1, 1, 5, 3, 2, 1, 7, 1, 2, 9, 1, 2, 16, 1, 1, 17, 11,   1, 4, 14, 13, 1, 19, 15, 1, 20, 10, 6, 1, 18, 12, 3), cd4_pass_result = c(1,   4, 18, 1, 1, 1, 5, 3, 2, 1, 20, 1, 2, 19, 1, 2, 12, 1, 1, 13,   6, 1, 10, 11, 9, 1, 17, 2, 1, 15, 7, 16, 1, 14, 8, 3), eid_perform_result = c(2,   1, 6, 1, 1, 1, 1, 8, 1, 1, 7, 1, 2, 3, 5, 2, 5, 1, 1, 9, 5, 1,   4, 2, 10, 1, 5, 1, 1, 5, 8, 2, 1, 1, 8, 5), eid_participate_result = c(2,   1, 4, 1, 1, 1, 1, 7, 1, 1, 6, 1, 2, 9, 4, 2, 4, 1, 1, 3, 2, 1,   9, 2, 8, 1, 4, 1, 1, 4, 6, 2, 1, 1, 5, 4), eid_pass_result = c(2,   1, 4, 1, 1, 1, 1, 6, 1, 1, 5, 1, 2, 9, 1, 2, 4, 1, 1, 3, 2, 1,   8, 2, 7, 1, 4, 1, 1, 4, 5, 2, 1, 1, 4, 4), vl_perform_result = c(2,   1, 3, 1, 1, 1, 1, 8, 1, 1, 9, 1, 2, 10, 4, 2, 4, 1, 1, 5, 4,   1, 7, 6, 5, 1, 11, 1, 1, 4, 8, 2, 1, 1, 7, 4), vl_participate_result = c(2,   1, 7, 1, 1, 1, 1, 7, 1, 1, 8, 1, 2, 8, 4, 2, 4, 1, 1, 5, 2, 1,   4, 6, 3, 1, 9, 1, 1, 4, 7, 2, 1, 1, 6, 1), vl_pass_result = c(2,   1, 7, 1, 1, 1, 1, 7, 1, 1, 9, 1, 2, 8, 1, 2, 5, 1, 1, 4, 2, 1,   2, 6, 3, 1, 10, 1, 1, 5, 7, 2, 1, 1, 5, 1), hiv_perform_result = c(18,   28, 13, 1, 1, 1, 25, 20, 10, 1, 6, 11, 9, 7, 19, 26, 8, 14, 1,   27, 12, 1, 24, 17, 23, 1, 21, 5, 1, 22, 16, 15, 1, 2, 3, 4),       hiv_participate_result = c(18, 27, 13, 1, 1, 1, 21, 19, 4,       1, 15, 9, 10, 3, 11, 26, 5, 1, 1, 20, 6, 1, 23, 17, 12, 1,       24, 8, 1, 22, 14, 16, 1, 2, 25, 7), hiv_pass_result = c(19,       27, 13, 1, 1, 1, 17, 21, 6, 1, 16, 26, 10, 2, 23, 25, 9,       1, 1, 14, 4, 1, 20, 18, 11, 1, 22, 7, 1, 15, 12, 8, 1, 3,       24, 5), tbafb_perform_result = c(9, 1, 8, 1, 1, 1, 1, 7,       1, 1, 6, 1, 20, 5, 1, 2, 12, 1, 1, 15, 13, 1, 17, 11, 19,       1, 10, 1, 1, 14, 16, 4, 1, 18, 3, 1), tbafb_participate_result = c(1,       1, 17, 1, 1, 1, 1, 5, 1, 1, 12, 1, 18, 11, 1, 2, 6, 1, 1,       13, 7, 1, 10, 9, 14, 1, 8, 1, 1, 16, 15, 4, 1, 17, 3, 1),       tbafb_pass_result = c(1, 1, 18, 1, 1, 1, 1, 6, 1, 1, 13,       1, 19, 11, 1, 2, 4, 1, 1, 15, 5, 1, 7, 10, 12, 1, 8, 1, 1,       16, 9, 3, 1, 14, 17, 1), tbculture_perform_result = c(3,       1, 2, 1, 1, 1, 1, 1, 1, 1, 6, 1, 3, 8, 1, 2, 2, 1, 1, 7,       3, 1, 5, 4, 7, 1, 5, 1, 1, 3, 6, 6, 1, 3, 3, 1), tbculture_participate_result = c(1,       1, 2, 1, 1, 1, 1, 1, 1, 1, 5, 1, 3, 8, 1, 2, 2, 1, 1, 7,       2, 1, 6, 4, 6, 1, 1, 1, 1, 3, 3, 5, 1, 3, 3, 1), tbculture_pass_result = c(1,       1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 7, 1, 2, 2, 1, 1, 8,       2, 1, 6, 4, 5, 1, 1, 1, 1, 3, 3, 6, 1, 3, 3, 1), tbxpert_perform_result = c(1,       1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 16, 1, 8, 3, 1, 1, 5,       9, 1, 15, 7, 13, 1, 4, 1, 1, 12, 11, 1, 1, 6, 14, 10), tbxpert_participate_result = c(1,       1, 5, 1, 1, 1, 1, 1, 1, 1, 15, 1, 1, 4, 1, 12, 3, 1, 1, 2,       7, 1, 16, 9, 11, 1, 1, 1, 1, 14, 10, 1, 1, 6, 8, 13), tbxpert_pass_result = c(1,       1, 2, 1, 1, 1, 1, 1, 1, 1, 12, 1, 1, 4, 1, 9, 3, 1, 1, 14,       6, 1, 13, 8, 8, 1, 1, 1, 1, 11, 6, 1, 1, 5, 7, 10)), .names = c("country",   "cd4_perform_result", "cd4_participate_result", "cd4_pass_result",   "eid_perform_result", "eid_participate_result", "eid_pass_result",   "vl_perform_result", "vl_participate_result", "vl_pass_result",   "hiv_perform_result", "hiv_participate_result", "hiv_pass_result",   "tbafb_perform_result", "tbafb_participate_result", "tbafb_pass_result",   "tbculture_perform_result", "tbculture_participate_result", "tbculture_pass_result",   "tbxpert_perform_result", "tbxpert_participate_result", "tbxpert_pass_result"  ), row.names = c(na, 36l), class = "data.frame")

it organized unique orgnationationunitname, columns grouped different categories. e.g. cd4, eid, vl, hiv, tbafb etc. , perform, participate & pass_result. want tabulate data across these categories

country: erkf  cat	         cd4	eid	vl	hiv 	tb afb 	tb culture	tb xpert  perform	        3442	288	114	29519	8572	72	        591  participate	1771	128	95	17342	5433	119	        395  pass_test	1535	118	83	11674	4508	109	        343

how can in r, without having create separate data frames?


Comments

Popular posts from this blog

xcode - CocoaPod Storyboard error: -

c# - AutoMapper - What's difference between Condition and PreCondition -