簡體   English   中英

當使用 dplyr group by 和 summarise() 時,is.factor(x) 中出現錯誤:缺少參數“x”,沒有默認值

[英]When using dplyr group by and summarise() I get Error in is.factor(x) : argument “x” is missing, with no default

一些要重現的數據:

> model_dat %>% sample_n(20) %>% dput()
structure(list(united_states = c(0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 
1, 0, 1, 1, 1, 1, 1, 0, 1, 1), paid_source = c(1, 0, 0, 1, 0, 
0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0), returner = c(1, 
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1), submissions = c(8, 
7, 8, 2, 23, 7, 21, 31, 4, 5, 33, 45, 11, 7, 27, 9, 14, 7, 7, 
11), sessions = c(27, 3, 12, 6, 57, 30, 33, 83, 3, 8, 36, 102, 
19, 40, 66, 32, 26, 5, 6, 26), d365_RPI = c(4.96, 0.34, 0.44, 
0.72, 1018.43, 0.56, 537.51, 149.34, 0.02, 34.58, 131.62, 5.98, 
17.35, 1.09, 21.67, 16.32, 132.86, 0.04, 815.52, 0.22), facebook_connected = c(1, 
0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1), avg_rating_received = c(3.91, 
0, 3.76, 0, 4.33, 4.42, 4.03, 4.35, 0, 4.26, 4.21, 4.25, 4.35, 
4.05, 4.41, 4, 4.23, 0, 3.96, 4.09), Spend_Distr_Accent_Chairs = c(0.158218087752462, 
0.193118944647128, 0.116177156177156, 0.0325616780784697, 0.137971746681127, 
0.0786682501330931, 0.18472923681257, 0.143933423698894, 0.126493273542601, 
0.103268694666544, 0.15158835806669, 0.135969572243601, 0.048991242548399, 
0.156694249946955, 0.0961558826644075, 0.179344128452851, 0.145752437656398, 
0.175608391608392, 0.0577726218097448, 0.0977782250962434), Spend_Distr_Accent_Tables = c(0.0475574569694558, 
0, 0.0201709401709402, 0.00865123356156939, 0.0182383547727242, 
0.0204144313853966, 0.0733638468013468, 0.0215196124788534, 0, 
0.0152865851790583, 0.0762050321287121, 0.0561324250243297, 0.0872638303656382, 
0.0416931890515595, 0.0401933129879757, 0.0160566063409988, 0.04607817758219, 
0.056027972027972, 0.021084686774942, 0.0656971038925094), Spend_Distr_Armchairs = c(0, 
0, 0.016006216006216, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0.0165563747074957), Spend_Distr_Beds = c(0, 0, 0.0433566433566434, 
0, 0, 0.0535648470453336, 0, 0.0293582994462483, 0, 0, 0.0152837351476606, 
0.029668848155853, 0.125050971863531, 0, 0.00951161514541796, 
0, 0.0183147812580896, 0.0276363636363636, 0, 0), Spend_Distr_Bedside_Tables = c(0.00992438563327032, 
0.0144482833603131, 0.0465889665889666, 0, 0.00739967875235101, 
0.0339284983005037, 0.00683922558922559, 0.0254809864556736, 
0, 0, 0.0279215763611563, 0.0292402882065659, 0.0155148643662984, 
0.0206874602164227, 0.0193698073609119, 0.0119517394656869, 0.00968590905168694, 
0.0136503496503496, 0.0288573085846868, 0.0122788918803311), 
    Spend_Distr_Benches = c(0.0329320465625311, 0.00719998067119283, 
    0.0465268065268065, 0, 0.0521341003006549, 0.0976288955321676, 
    0.0192462822671156, 0.0247349452027446, 0.035695067264574, 
    0.0487700272646509, 0.0140429587996516, 0.00440166781246931, 
    0.0981378279189887, 0.0289624443029917, 0.0311052920393172, 
    0.0204109402639815, 0.0345262749158685, 0.0137902097902098, 
    0.0397041763341067, 0.0509272073069471), Spend_Distr_Chaises = c(0, 
    0, 0, 0, 0, 0, 0, 0.0199539766100306, 0, 0, 0.00790481355486532, 
    0.0147317482567431, 0, 0, 0.0261954502132412, 0, 0, 0.0781818181818182, 
    0, 0), Spend_Distr_Cocktail_Tables = c(0.114192617649985, 
    0.1189204861195, 0.0523387723387723, 0.0195196174328877, 
    0.140264411526475, 0.0748392645071461, 0.109646815375982, 
    0.0572665468797613, 0.203695067264574, 0.221058113531232, 
    0.118999490542162, 0.101818701284787, 0.0483310355540884, 
    0.116963717377467, 0.106764991865066, 0.0739783190456751, 
    0.109166019501251, 0.132307692307692, 0.0538573085846868, 
    0.105653825830964), Spend_Distr_Console_Tables = c(0.0204457267933539, 
    0, 0, 0, 0.00774289205255282, 0, 0.0397639590347924, 0.0297470815076338, 
    0, 0, 0.0172476129435159, 0.0162852780729088, 0, 0, 0.00335024501073426, 
    0, 0.0678552938130986, 0.0256783216783217, 0.0253190255220418, 
    0.0188209244395239), Spend_Distr_Desks = c(0, 0, 0, 0, 0.00665147375791107, 
    0, 0, 0.0115478779854785, 0, 0, 0.0221531989022005, 0.0133032150924529, 
    0, 0.0423032039040951, 0.0156248495759244, 0.0809633963804599, 
    0, 0.0447552447552448, 0, 0.0160531414337116), Spend_Distr_Dining_Tables = c(0.0248234006566511, 
    0.10584938027012, 0.0290909090909091, 0.010651016193892, 
    0.0522302000247114, 0.0200253900651132, 0, 0.0932866794859671, 
    0.0537757847533632, 0, 0.016820325724334, 0.0490968991902003, 
    0.0344278529680188, 0, 0.0229222223291905, 0, 0, 0.0415664335664336, 
    0.0289443155452436, 0.0163047580706036), Spend_Distr_Dressers = c(0.0898418067853945, 
    0.0700186039769021, 0.0279098679098679, 0, 0, 0.0306728367255006, 
    0.0223063973063973, 0.0131135138543013, 0, 0, 0.0151769133428651, 
    0.025874306938207, 0.0483310355540884, 0, 0.0415507398457732, 
    0.0355603937043589, 0.0118539131935456, 0, 0, 0.0314017562841255
    ), Spend_Distr_Floor_Decor = c(0, 0, 0, 0, 0.00652105270383438, 
    0, 0, 0, 0, 0.0245075513892718, 0.011093033574915, 0, 0, 
    0.0238701464035646, 0, 0, 0, 0, 0, 0), Spend_Distr_Floor_Lamps = c(0.0163665306934633, 
    0, 0, 0, 0.00568361225134196, 0, 0.00624298540965208, 0.00366716052496086, 
    0, 0, 0.014100478233003, 0.019776255993143, 0.0135536612361405, 
    0, 0.0296034580689881, 0, 0.016502718094745, 0, 0, 0), Spend_Distr_Floor_Plants = c(0.0460153218585215, 
    0.0144966053782406, 0.0481740481740482, 0.120639060971634, 
    0.00617783940363257, 0, 0.0105218855218855, 0.0283705828578634, 
    0, 0.0275709953129308, 0.00657364952587553, 0.026784996830442, 
    0.0300976717994524, 0.0212179079142797, 0.0259932802556969, 
    0, 0, 0, 0.0275522041763341, 0.0150969982135219), Spend_Distr_Garden_Stools = c(0, 
    0, 0.00304584304584305, 0, 0.00412542386842575, 0, 0, 0.00240624573127804, 
    0, 0.0184112979811905, 0.00433860868707785, 0.000874976563127773, 
    0, 0.00259919371949926, 0.00608435300800015, 0, 0.0136875485374062, 
    0, 0, 0), Spend_Distr_Ottomans = c(0.0310168142473386, 0.0287516006668438, 
    0.0306138306138306, 0, 0.0218901442868714, 0.0411974282321143, 
    0.0423856621773288, 0.0503630383843478, 0.0223497757847534, 
    0.0274178231167478, 0.0325724334007132, 0.05150754890494, 
    0.0975358744829997, 0.0401283683428814, 0.0517458819905076, 
    0.0594638726357328, 0.0425187677970489, 0.050041958041958, 
    0.0340197215777262, 0.0681126236066729), Spend_Distr_Rugs = c(0.0775047258979206, 
    0.0795863635265409, 0.193473193473193, 0.0649929355504836, 
    0.172581375873478, 0.114398624022278, 0.129077230639731, 
    0.0625623890132291, 0.0469237668161435, 0.0961002358851821, 
    0.0580535423753883, 0.0512754122657429, 0.0500398065981864, 
    0.119536388712073, 0.105811904922357, 0.0437247698099515, 
    0.110028906721891, 0.0248671328671329, 0.0849187935034803, 
    0.017839619555645), Spend_Distr_Sectionals = c(0, 0.0410253932204209, 
    0, 0, 0.0115868810148131, 0.0448011794094762, 0, 0, 0, 0, 
    0.0164176896908741, 0.0418381650491505, 0.0401755373890755, 
    0, 0.0192350273892157, 0, 0, 0.0556083916083916, 0, 0.0502730040510279
    ), Spend_Distr_Side_Chairs = c(0.0321858521540145, 0.0549662953924956, 
    0, 0.0193457232909466, 0.0120536511030875, 0, 0, 0.0381006420157824, 
    0.0214887892376682, 0, 0.0153823398905487, 0.0363025990375258, 
    0.0165051748577642, 0.0277158922130278, 0.0110038219749117, 
    0.0146731981675511, 0, 0.0391048951048951, 0.00954176334106729, 
    0.00500717107415142), Spend_Distr_Sideboards = c(0.0146254104069247, 
    0.078668245185919, 0.0434809634809635, 0.0629279426149332, 
    0.0655468760725416, 0.121995167697285, 0.0515046296296296, 
    0.0544294885939749, 0.14704932735426, 0, 0.0592450163519532, 
    0.0342133692847513, 0.0712635196799938, 0, 0.0552886698179508, 
    0.0263981494080827, 0.0537902321166624, 0, 0.0721577726218098, 
    0.0233500239035805), Spend_Distr_Sofas = c(0.122549995025371, 
    0.0287032786489164, 0.121243201243201, 0.106205847190523, 
    0.111400172979503, 0.242147508087964, 0.131584946689113, 
    0.0922569324044594, 0.244412556053812, 0.209508929939037, 
    0.132056401912932, 0.117773631063454, 0, 0.133513685550605, 
    0.10217284568656, 0.180500748401143, 0.185833549055138, 0.14165034965035, 
    0.342053364269142, 0.194977731927635), Spend_Distr_Stools = c(0.0142523132026664, 
    0.0806252869119814, 0.0102253302253302, 0, 0.0109073186804135, 
    0.0161349768622794, 0.0371773288439955, 0.0219083945402389, 
    0.0245739910313901, 0, 0.0280612664135812, 0.025490388650304, 
    0.0163109963300258, 0.00445576066199873, 0.00723960990825335, 
    0.0425681498616592, 0.0243226335317974, 0.0104335664335664, 
    0.0462006960556845, 0.00347230958911003), Spend_Distr_Table_Lamps = c(0.0190777037110735, 
    0.0113073521950277, 0.0588344988344988, 0.00239104445169003, 
    0.0115182383547727, 0, 0.0259452160493827, 0.0299887568430897, 
    0, 0, 0.0174283883054775, 0.0190709177432747, 0.0566612943940659, 
    0.0102376405686399, 0.0261954502132412, 0.0649294688619767, 
    0.036316765898697, 0.0301538461538462, 0.0213457076566125, 
    0.0343205092720731), Spend_Distr_Tall_Dressers = c(0, 0, 
    0, 0, 0, 0, 0, 0.0216772268280638, 0, 0, 0, 0, 0, 0, 0.0114370433125066, 
    0, 0, 0, 0, 0), Spend_Distr_Tall_Shelves = c(0, 0, 0, 0, 
    0.0307381831660741, 0.00958270199434866, 0.0451476571268238, 
    0, 0, 0.0469625953496921, 0, 0.0266064301849058, 0.0431076331579254, 
    0, 0.0301810865191147, 0.0226334648705039, 0, 0.0314125874125874, 
    0.0254930394431555, 0), Spend_Distr_Twin_Beds = c(0, 0.0216241030225422, 
    0.0170629370629371, 0, 0, 0, 0.0280057519640853, 0.0482299908583677, 
    0, 0, 0.0440105835757367, 0.0233208039070382, 0, 0.0477402928071292, 
    0.00865479961106351, 0.0747040413661723, 0.00969669514194495, 
    0, 0, 0.0440329114561055), submissionsSqd = c(64, 49, 64, 
    4, 529, 49, 441, 961, 16, 25, 1089, 2025, 121, 49, 729, 81, 
    196, 49, 49, 121), sessionsSqd = c(729, 9, 144, 36, 3249, 
    900, 1089, 6889, 9, 64, 1296, 10404, 361, 1600, 4356, 1024, 
    676, 25, 36, 676), avg_rating_receivedSqd = c(15.2881, 0, 
    14.1376, 0, 18.7489, 19.5364, 16.2409, 18.9225, 0, 18.1476, 
    17.7241, 18.0625, 18.9225, 16.4025, 19.4481, 16, 17.8929, 
    0, 15.6816, 16.7281), fb_x_sessions = c(27, 0, 0, 0, 57, 
    0, 0, 83, 3, 0, 36, 102, 19, 40, 0, 0, 26, 0, 0, 26), fb_x_united_states = c(0, 
    0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1)), class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L))

如果上面的示例代碼是變量“model_dat”,我正在嘗試運行這個代碼塊:

filtered_row <- model_dat %>%
    group_by(united_states, facebook_connected, paid_source, returner, sessions, avg_rating_received, submissions) %>% 
    summarise_all(median())

這導致:

is.factor(x) 中的錯誤:缺少參數“x”,沒有默認值

如何減少我的 dataframe 並按中值總結剩余特征?

在評論中回答:

filtered_row <- model_dat %>%
    group_by(united_states, facebook_connected, paid_source, returner, sessions, avg_rating_received, submissions) %>% 
    summarise_all(median)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM