它只花了最后几个小时试图编写一个函数来巧妙地提取大型列表的特定值。 该列表是Matching-package中MatchBalance-function的结果。 (如下所示)
dput(match_balance)
list(BeforeMatching = list(structure(list(sdiff = 22.2584906974256,
sdiff.pooled = 21.4958513408818, mean.Tr = 0.698535745047373,
mean.Co = 0.596348884381339, var.Tr = 0.210765095488431,
var.Co = 0.241206154455054, p.value = 8.60322780498191e-05,
var.ratio = 0.873796508072539, tt = list(statistic = 3.94546943651756,
parameter = Inf, p.value = 8.60322780498191e-05, estimate = 0.102186860666034),
qqsummary = list(meandiff = 0.0510934303330171, mediandiff = 0.0510934303330171,
maxdiff = 0.102186860666034), qqsummary.raw = list(meandiff = 0.101419878296146,
mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 5.3973084293699, sdiff.pooled = 5.92345489633794,
mean.Tr = 8.08527131782946, mean.Co = 7.81947261663286,
var.Tr = 24.2522052927025, var.Co = 16.0181566318706,
p.value = 0.250207681820269, var.ratio = 1.51404470876811,
ks = list(ks = list(p.value = 0.114246870617229, statistic = 0.064309462535794),
ks.boot.pvalue = 0.036), tt = list(statistic = 1.15043617596334,
parameter = Inf, p.value = 0.250207681820269, estimate = 0.265798701196598),
qqsummary = list(meandiff = 0.0204640823995788, mediandiff = 0.0135733167008227,
maxdiff = 0.0643094625357939), qqsummary.raw = list(
meandiff = 0.72210953346856, mediandiff = 0, maxdiff = 10)), class = "balanceUV"),
structure(list(sdiff = 12.2671863050276, sdiff.pooled = 12.5477798990104,
mean.Tr = 0.354866494401378, mean.Co = 0.296146044624746,
var.Tr = 0.229133624402269, var.Co = 0.208867230660136,
p.value = 0.0186553005651673, var.ratio = 1.09703003040774,
tt = list(statistic = 2.35632374880165, parameter = Inf,
p.value = 0.0186553005651673, estimate = 0.0587204497766317),
qqsummary = list(meandiff = 0.0293602248883158, mediandiff = 0.0293602248883158,
maxdiff = 0.0587204497766316), qqsummary.raw = list(
meandiff = 0.0588235294117647, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = -4.35451566570258, sdiff.pooled = -4.27827299751805,
mean.Tr = 0.180017226528854, mean.Co = 0.196754563894523,
var.Tr = 0.14773827556506, var.Co = 0.15836342947608,
p.value = 0.429534065280635, var.ratio = 0.93290651796206,
tt = list(statistic = -0.790346091204352, parameter = Inf,
p.value = 0.429534065280635, estimate = -0.0167373373656689),
qqsummary = list(meandiff = 0.00836866868283442, mediandiff = 0.00836866868283442,
maxdiff = 0.0167373373656688), qqsummary.raw = list(
meandiff = 0.0162271805273834, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 39.9822573084269, sdiff.pooled = 36.6629816770573,
mean.Tr = 0.7786391042205, mean.Co = 0.612576064908722,
var.Tr = 0.172508836021266, var.Co = 0.237809000808061,
p.value = 6.92215174069588e-11, var.ratio = 0.725409195762528,
tt = list(statistic = 6.61108722554289, parameter = Inf,
p.value = 6.92215174069588e-11, estimate = 0.166063039311777),
qqsummary = list(meandiff = 0.0830315196558887, mediandiff = 0.0830315196558887,
maxdiff = 0.166063039311777), qqsummary.raw = list(
meandiff = 0.164300202839757, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 12.597525525777, sdiff.pooled = 13.5632307793938,
mean.Tr = 0.141257536606374, mean.Co = 0.0973630831643002,
var.Tr = 0.121408417238409, var.Co = 0.0880621382278731,
p.value = 0.00922374798002057, var.ratio = 1.37866760541571,
tt = list(statistic = 2.60834531296045, parameter = Inf,
p.value = 0.00922374798002057, estimate = 0.0438944534420736),
qqsummary = list(meandiff = 0.0219472267210368, mediandiff = 0.0219472267210368,
maxdiff = 0.0438944534420737), qqsummary.raw = list(
meandiff = 0.0446247464503043, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 21.7153523183508, sdiff.pooled = 28.3845616356215,
mean.Tr = 0.0628768303186908, mean.Co = 0.0101419878296146,
var.Tr = 0.0589741305058065, var.Co = 0.010059532644008,
p.value = 5.2243853687628e-10, var.ratio = 5.86251196678951,
tt = list(statistic = 6.24964706630044, parameter = Inf,
p.value = 5.2243853687628e-10, estimate = 0.0527348424890762),
qqsummary = list(meandiff = 0.0263674212445381, mediandiff = 0.0263674212445381,
maxdiff = 0.0527348424890761), qqsummary.raw = list(
meandiff = 0.0527383367139959, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = -39.0787955789784, sdiff.pooled = -47.8011511924565,
mean.Tr = 0.773471145564169, mean.Co = 0.937119675456389,
var.Tr = 0.175364578692566, var.Co = 0.0590461584129026,
p.value = 0, var.ratio = 2.9699574605051, tt = list(statistic = -9.94433082519833,
parameter = Inf, p.value = 0, estimate = -0.163648529892221),
qqsummary = list(meandiff = 0.0818242649461103, mediandiff = 0.0818242649461103,
maxdiff = 0.163648529892221), qqsummary.raw = list(
meandiff = 0.164300202839757, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = -3.98851571987444, sdiff.pooled = -3.98818429650864,
mean.Tr = 0.49526270456503, mean.Co = 0.515212981744422,
var.Tr = 0.250193055926817, var.Co = 0.250276224871782,
p.value = 0.458349108088805, var.ratio = 0.999667691387754,
tt = list(statistic = -0.741877948762809, parameter = Inf,
p.value = 0.458349108088805, estimate = -0.0199502771793917),
qqsummary = list(meandiff = 0.00997513858969587, mediandiff = 0.00997513858969587,
maxdiff = 0.0199502771793917), qqsummary.raw = list(
meandiff = 0.0202839756592292, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 12.5540247631196, sdiff.pooled = 14.0760164750664,
mean.Tr = 0.078380706287683, mean.Co = 0.0446247464503043,
var.Tr = 0.072299444592949, var.Co = 0.0427200316627913,
p.value = 0.00576113754555174, var.ratio = 1.69240147487815,
tt = list(statistic = 2.76607707952665, parameter = Inf,
p.value = 0.00576113754555174, estimate = 0.0337559598373788),
qqsummary = list(meandiff = 0.0168779799186894, mediandiff = 0.0168779799186894,
maxdiff = 0.0337559598373788), qqsummary.raw = list(
meandiff = 0.0344827586206897, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 13.3315397848797, sdiff.pooled = 13.7265855346641,
mean.Tr = 0.507957655455033, mean.Co = 0.472143828112388,
var.Tr = 0.0721673644211338, var.Co = 0.0639791181344331,
p.value = 0.0098790313533379, var.ratio = 1.12798310644882,
ks = list(ks = list(p.value = 0.00266655156614348, statistic = 0.0978016083917306),
ks.boot.pvalue = 0.001), tt = list(statistic = 2.58507967777527,
parameter = Inf, p.value = 0.0098790313533379, estimate = 0.0358138273426449),
qqsummary = list(meandiff = 0.0499856602385024, mediandiff = 0.0440420844449337,
maxdiff = 0.0978016083917306), qqsummary.raw = list(
meandiff = 0.0442845670492144, mediandiff = 0.0476190476190476,
maxdiff = 0.142857142857143)), class = "balanceUV"),
structure(list(sdiff = 4.87227042076281, sdiff.pooled = 4.98405738715444,
mean.Tr = 0.278638322937648, mean.Co = 0.265922140872028,
var.Tr = 0.0681162460692791, var.Co = 0.0620736864689898,
p.value = 0.349519842043573, var.ratio = 1.09734494508084,
ks = list(ks = list(p.value = 0.506111511162152, statistic = 0.0442788181832476),
ks.boot.pvalue = 0.353), tt = list(statistic = 0.93597424972811,
parameter = Inf, p.value = 0.349519842043573, estimate = 0.0127161820656209),
qqsummary = list(meandiff = 0.0218282465977588, mediandiff = 0.0213322431351584,
maxdiff = 0.0442788181832476), qqsummary.raw = list(
meandiff = 0.0189052460056224, mediandiff = 0.00476190476190477,
maxdiff = 0.1)), class = "balanceUV"), structure(list(
sdiff = 50.8455723559418, sdiff.pooled = 57.1984691101715,
mean.Tr = 12.4720068906115, mean.Co = 7.18255578093306,
var.Tr = 108.221845020642, var.Co = 62.8121341051139,
p.value = 0, var.ratio = 1.7229448825849, ks = list(ks = list(
p.value = 0, statistic = 0.283000770476595), ks.boot.pvalue = 0),
tt = list(statistic = 11.2612315121661, parameter = Inf,
p.value = 0, estimate = 5.28945110967848), qqsummary = list(
meandiff = 0.120195222346267, mediandiff = 0.123624804105015,
maxdiff = 0.283000770476595), qqsummary.raw = list(
meandiff = 5.28600405679513, mediandiff = 5, maxdiff = 12)), class = "balanceUV"),
structure(list(sdiff = -149.790452098093, sdiff.pooled = -98.4174509729638,
mean.Tr = 0.0740740740740741, mean.Co = 0.466531440162272,
var.Tr = 0.0686462324393359, var.Co = 0.249385708867231,
p.value = 0, var.ratio = 0.275261292040925, tt = list(
statistic = -16.51109508659, parameter = Inf, p.value = 0,
estimate = -0.392457366088198), qqsummary = list(
meandiff = 0.196228683044099, mediandiff = 0.196228683044099,
maxdiff = 0.392457366088198), qqsummary.raw = list(
meandiff = 0.391480730223124, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = -2.25163812152155, sdiff.pooled = -2.24203587782247,
mean.Tr = 0.328165374677003, mean.Co = 0.338742393509128,
var.Tr = 0.220662924351778, var.Co = 0.224451260739788,
p.value = 0.677243477403197, var.ratio = 0.983121786103923,
tt = list(statistic = -0.416360243198386, parameter = Inf,
p.value = 0.677243477403197, estimate = -0.0105770188321252),
qqsummary = list(meandiff = 0.00528850941606263, mediandiff = 0.00528850941606263,
maxdiff = 0.0105770188321253), qqsummary.raw = list(
meandiff = 0.0101419878296146, mediandiff = 0, maxdiff = 1)), class = "balanceUV")),
AfterMatching = list(structure(list(sdiff = 5.62846137589845,
sdiff.pooled = 5.62846137589845, mean.Tr = 0.698535745047373,
mean.Co = 0.672695951765719, var.Tr = 0.210583557938485,
var.Co = 0.220176108243732, p.value = 0.0646992301558937,
var.ratio = 0.956432374149201, tt = list(statistic = 1.84908913783282,
parameter = Inf, p.value = 0.0646992301558937, estimate = 0.0258397932816537),
qqsummary = list(meandiff = 0.0129198966408269, mediandiff = 0.0129198966408269,
maxdiff = 0.0258397932816538), qqsummary.raw = list(
meandiff = 0.0258397932816537, mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 4.16264255174112, sdiff.pooled = 4.16264255174112,
mean.Tr = 8.08527131782946, mean.Co = 7.88027562446167,
var.Tr = 24.2313162269896, var.Co = 19.1234783047374,
p.value = 0.0298269273944689, var.ratio = 1.26709774450325,
ks = list(ks = list(p.value = 0.147671007224485,
statistic = 0.0473729543496985), ks.boot.pvalue = 0.046),
tt = list(statistic = 2.17506198797969, parameter = Inf,
p.value = 0.0298269273944689, estimate = 0.204995693367786),
qqsummary = list(meandiff = 0.0135985174744865, mediandiff = 0.00775193798449603,
maxdiff = 0.0473729543496986), qqsummary.raw = list(
meandiff = 0.463393626184324, mediandiff = 0,
maxdiff = 18)), class = "balanceUV"), structure(list(
sdiff = 3.77870216649659, sdiff.pooled = 3.77870216649659,
mean.Tr = 0.354866494401378, mean.Co = 0.336778639104221,
var.Tr = 0.228936265552655, var.Co = 0.22335878734733,
p.value = 0.000751164709090091, var.ratio = 1.0249709369914,
tt = list(statistic = 3.37918748651929, parameter = Inf,
p.value = 0.000751164709090091, estimate = 0.0180878552971576),
qqsummary = list(meandiff = 0.00904392764857881,
mediandiff = 0.00904392764857881, maxdiff = 0.0180878552971576),
qqsummary.raw = list(meandiff = 0.0180878552971576,
mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 1.79271500892808, sdiff.pooled = 1.79271500892808,
mean.Tr = 0.180017226528854, mean.Co = 0.17312661498708,
var.Tr = 0.147611024681714, var.Co = 0.143153790170195,
p.value = 0.0453608072305189, var.ratio = 1.031135986733,
tt = list(statistic = 2.00345423400722, parameter = Inf,
p.value = 0.0453608072305189, estimate = 0.00689061154177433),
qqsummary = list(meandiff = 0.00344530577088714,
mediandiff = 0.00344530577088714, maxdiff = 0.00689061154177428),
qqsummary.raw = list(meandiff = 0.00689061154177433,
mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 0, sdiff.pooled = 0, mean.Tr = 0.7786391042205,
mean.Co = 0.7786391042205, var.Tr = 0.172360249599198,
var.Co = 0.172360249599198, p.value = 1, var.ratio = 1,
tt = list(statistic = 0, parameter = Inf, p.value = 1,
estimate = 0), qqsummary = list(meandiff = 0,
mediandiff = 0, maxdiff = 0), qqsummary.raw = list(
meandiff = 0, mediandiff = 0, maxdiff = 0)), class = "balanceUV"),
structure(list(sdiff = 0.988788422895726, sdiff.pooled = 0.988788422895726,
mean.Tr = 0.141257536606374, mean.Co = 0.137812230835487,
var.Tr = 0.121303844958273, var.Co = 0.118820019867633,
p.value = 0.0453608072305187, var.ratio = 1.0209040959041,
tt = list(statistic = 2.00345423400722, parameter = Inf,
p.value = 0.0453608072305187, estimate = 0.00344530577088717),
qqsummary = list(meandiff = 0.0017226528854436, mediandiff = 0.0017226528854436,
maxdiff = 0.0034453057708872), qqsummary.raw = list(
meandiff = 0.00344530577088717, mediandiff = 0,
maxdiff = 1)), class = "balanceUV"), structure(list(
sdiff = 0, sdiff.pooled = 0, mean.Tr = 0.0628768303186908,
mean.Co = 0.0628768303186908, var.Tr = 0.0589233345277653,
var.Co = 0.0589233345277653, p.value = 1, var.ratio = 1,
tt = list(statistic = 0, parameter = Inf, p.value = 1,
estimate = 0), qqsummary = list(meandiff = 0,
mediandiff = 0, maxdiff = 0), qqsummary.raw = list(
meandiff = 0, mediandiff = 0, maxdiff = 0)), class = "balanceUV"),
structure(list(sdiff = 1.23409357862471, sdiff.pooled = 1.23409357862471,
mean.Tr = 0.773471145564169, mean.Co = 0.768303186907838,
var.Tr = 0.175213532543821, var.Co = 0.178013399895098,
p.value = 0.0142012433926924, var.ratio = 0.984271592178305,
tt = list(statistic = 2.45584381245405, parameter = Inf,
p.value = 0.0142012433926924, estimate = 0.00516795865633075),
qqsummary = list(meandiff = 0.00258397932816537,
mediandiff = 0.00258397932816537, maxdiff = 0.00516795865633074),
qqsummary.raw = list(meandiff = 0.00516795865633075,
mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = -2.41078338721197, sdiff.pooled = -2.41078338721197,
mean.Tr = 0.49526270456503, mean.Co = 0.507321274763135,
var.Tr = 0.249977558031962, var.Co = 0.249946398935843,
p.value = 0.439549902808192, var.ratio = 1.00012466311278,
tt = list(statistic = -0.773219694316945, parameter = Inf,
p.value = 0.439549902808192, estimate = -0.0120585701981051),
qqsummary = list(meandiff = 0.00602928509905251,
mediandiff = 0.00602928509905251, maxdiff = 0.012058570198105),
qqsummary.raw = list(meandiff = 0.0120585701981051,
mediandiff = 0, maxdiff = 1)), class = "balanceUV"),
structure(list(sdiff = 9.930291416322, sdiff.pooled = 9.930291416322,
mean.Tr = 0.078380706287683, mean.Co = 0.0516795865633075,
var.Tr = 0.072237171169527, var.Co = 0.0490088068959531,
p.value = 1.91987685069783e-05, var.ratio = 1.47396306388132,
tt = list(statistic = 4.29182343516133, parameter = Inf,
p.value = 1.91987685069783e-05, estimate = 0.0267011197243755),
qqsummary = list(meandiff = 0.0133505598621877, mediandiff = 0.0133505598621877,
maxdiff = 0.0267011197243755), qqsummary.raw = list(
meandiff = 0.0267011197243755, mediandiff = 0,
maxdiff = 1)), class = "balanceUV"), structure(list(
sdiff = 3.43987547209015, sdiff.pooled = 3.43987547209015,
mean.Tr = 0.507957655455033, mean.Co = 0.498716779440294,
var.Tr = 0.0721052047618564, var.Co = 0.0558416070884326,
p.value = 0.147042640388033, var.ratio = 1.29124515789218,
ks = list(ks = list(p.value = 0.000104306251282216,
statistic = 0.0921619293712317), ks.boot.pvalue = 0),
tt = list(statistic = 1.45102722479205, parameter = Inf,
p.value = 0.147042640388033, estimate = 0.00924087601473921),
qqsummary = list(meandiff = 0.0266073118939801, mediandiff = 0.0206718346253231,
maxdiff = 0.0921619293712318), qqsummary.raw = list(
meandiff = 0.0289282207814133, mediandiff = 0,
maxdiff = 0.2)), class = "balanceUV"), structure(list(
sdiff = 9.10109642166626, sdiff.pooled = 9.10109642166626,
mean.Tr = 0.278638322937648, mean.Co = 0.254885290141788,
var.Tr = 0.0680575757453607, var.Co = 0.0560004220033455,
p.value = 1.00565747906955e-06, var.ratio = 1.21530469433418,
ks = list(ks = list(p.value = 0.000305596833701904,
statistic = 0.0869939707149009), ks.boot.pvalue = 0),
tt = list(statistic = 4.91691414265496, parameter = Inf,
p.value = 1.00565747906955e-06, estimate = 0.0237530327958603),
qqsummary = list(meandiff = 0.0314248152681445, mediandiff = 0.0267011197243756,
maxdiff = 0.086993970714901), qqsummary.raw = list(
meandiff = 0.0300438995760228, mediandiff = 0.0166666666666667,
maxdiff = 0.25)), class = "balanceUV"), structure(list(
sdiff = 25.6005796438011, sdiff.pooled = 25.6005796438011,
mean.Tr = 12.4720068906115, mean.Co = 9.80878552971576,
var.Tr = 108.128630683846, var.Co = 88.5301898256649,
p.value = 0, var.ratio = 1.22137579165677, ks = list(
ks = list(p.value = 3.24185123190546e-14, statistic = 0.165374677002584),
ks.boot.pvalue = 0), tt = list(statistic = 13.1779461905435,
parameter = Inf, p.value = 0, estimate = 2.66322136089578),
qqsummary = list(meandiff = 0.0610562994283924, mediandiff = 0.0486649440137812,
maxdiff = 0.165374677002584), qqsummary.raw = list(
meandiff = 2.68733850129199, mediandiff = 3,
maxdiff = 8)), class = "balanceUV"), structure(list(
sdiff = 0, sdiff.pooled = 0, mean.Tr = 0.0740740740740741,
mean.Co = 0.0740740740740741, var.Tr = 0.0685871056241427,
var.Co = 0.0685871056241427, p.value = 1, var.ratio = 1,
tt = list(statistic = 0, parameter = Inf, p.value = 1,
estimate = 0), qqsummary = list(meandiff = 0,
mediandiff = 0, maxdiff = 0), qqsummary.raw = list(
meandiff = 0, mediandiff = 0, maxdiff = 0)), class = "balanceUV"),
structure(list(sdiff = 0, sdiff.pooled = 0, mean.Tr = 0.328165374677003,
mean.Co = 0.328165374677003, var.Tr = 0.220472861540105,
var.Co = 0.220472861540105, p.value = 1, var.ratio = 1,
tt = list(statistic = 0, parameter = Inf, p.value = 1,
estimate = 0), qqsummary = list(meandiff = 0,
mediandiff = 0, maxdiff = 0), qqsummary.raw = list(
meandiff = 0, mediandiff = 0, maxdiff = 0)), class = "balanceUV")),
BMsmallest.p.value = 0, BMsmallestVarName = c("RForm3", "F06A",
"VERSION2"), BMsmallestVarNumber = c(8, 13, 14), AMsmallest.p.value = 0,
AMsmallestVarName = c("C06A_ratio", "C06B_ratio", "F06A"),
AMsmallestVarNumber = c(11, 12, 13))
我想为每个变量(这里是n = 15)提取SMD('sdiff')和列表中的p.value“BeforeMatching”以及“AfterMatching”
我尝试写这个函数:
SMDeepExtract <- function(data) {
data = data
n = 1:(max(length(data[['BeforeMatching']])))
for (i in n) {
SMD_bef <- rbind(data[['BeforeMatching']][[i]][['sdiff']])
p.value_bef <- rbind(data[['BeforeMatching']][[i]][['p.value']])
SMD_aft <- rbind(data[['AfterMatching']][[i]][['sdiff']])
p.value_aft <- rbind(data[['AfterMatching']][[i]][['p.value']])
}
final <- cbind(SMD_bef, p.value_bef, SMD_aft, p.value_aft)
return(final)
}
SMDeepExtract(match_balance)
> SMDeepExtract(match_balance)
[,1] [,2] [,3] [,4]
[1,] -2.251638 0.6772435 0 1
看来,我的代码只粘贴了最后一个变量n15的结果而不是全部 - 有没有人看到我的错误?
谢谢!
答案 0 :(得分:0)
使用 sapply 而不是for循环:
<?php
$name = $_GET['name'];
$action = empty($_GET['action'])?'':$_GET['action'];
if(empty($name)){
exit('No data');
}
require_once("../winphplib/kernel.php");
require_once ('../winphplib/dbconnect_egen.php');
if($action=='get_name'){
$sqlquery = "SELECT rt_name FROM reg_ticket WHERE rt_name LIKE '%$name%' LIMIT 15";
$result = mysql_query($sqlquery) or die(mysql_error());
while($myrow = MySQL_fetch_array($result)){
$data[] = strtoupper($myrow['rt_name']);
}
}elseif($action=='get_fulldata') {
$sqlquery = "SELECT * FROM reg_ticket WHERE rt_name = '$name' LIMIT 1";
$result = mysql_query($sqlquery) or die(mysql_error());
$data = mysql_fetch_assoc($result);
if(count($data)>0){
list($data['mobile1'], $data['mobile2']) = explode("-", $data['rt_contact']);
list($data['tf1'], $data['tf2'], $data['tf3']) = explode("-", $data['rt_ic']);
}
}
mysql_free_result($result);
echo json_encode($data);