data.frame列长度不等于

时间:2017-09-05 19:16:28

标签: r

这完全是奇怪的。我有一个20列和200行的数据框。当我拿行数

nrow(df)

我得到200.但是当我单独调用一些列并占用它们的长度时,例如,

length(df$x3)

我得到的数字与200略有不同,例如207,203等。这仅适用于某些列,而其余列的长度为200.

我通过强制使用使用wordVectors包训练的word2vec模型创建的VectorSpaceModel对象来创建此data.frame。这或多或少都是我做的:

term_vec <- c("word1", "word2", "word3", ..., "word20")
properties <- model[[term_vec, average = F]]
df_prop <- as.data.frame(t(properties))
然后

df_prop是具有20列和200行的data.frame,但是当单独调用时,其列的长度不同。

编辑:

str(df_prop)

'data.frame':   200 obs. of  20 variables:
 $ activ         : num  -0.02795 0.00135 0.25447 0.02538 -0.02762 ...
 $ protein       : num  -0.0374 -0.2037 0.1852 -0.229 0.0437 ...
 $ cancer        : num  -0.2043 0.0144 0.1125 0.0405 0.09 ...
 $ role          : num  -0.1164 -0.2313 -0.0207 0.1405 -0.1694 ...
 $ oncogen       : num  -0.19599 -0.0771 0.00398 0.06351 -0.1299 ...
 $ loss          : num  -0.17479 -0.4214 0.28711 -0.07563 -0.00643 ...
 $ missens       : num  -0.1502 -0.4113 -0.0141 -0.1355 -0.0793 ...
 $ recurr        : num  0.16952 -0.31017 -0.00389 -0.06503 -0.03874 ...
 $ driver        : num  0.1928 -0.1774 -0.1946 -0.2157 -0.0734 ...
 $ cbl           : num  0.0593 -0.4683 -0.0712 0.184 0.1519 ...
 $ gain          : num  0.128 -0.313 0.251 -0.135 0.101 ...
 $ neutral       : num  0.06243 0.10662 -0.24245 -0.00875 -0.06072 ...
 $ polymorph     : num  0.0526 -0.2005 0.1147 -0.2716 0.2272 ...
 $ deleteri      : num  0.0705 -0.1022 -0.289 0.1769 -0.0114 ...
 $ loh           : num  -0.0133 -0.533 0.2306 -0.0127 0.1488 ...
 $ switch        : num  -0.1088 0.0453 -0.1768 0.1646 0.0477 ...
 $ passeng       : num  0.4528 -0.3491 0.2232 -0.2857 -0.0531 ...
 $ inconclus     : num  0.56665 0.00575 0.10589 -0.09961 -0.00753 ...
 $ heterozygosity: num  -0.0212 -0.7096 0.4345 -0.0401 0.0158 ...
 $ q249e         : num  -0.382 -0.673 -0.153 0.145 -0.18 ...

但是

length(df_prop$driver)
[1] 207

> linmod <- lm(passeng ~ neutral + driver, data = df_prop)
Error in model.frame.default(formula = passeng ~ neutral + driver, data = df_prop,  : 
  variable lengths differ (found for 'driver')

> str(df_prop$driver)
 num [1:207] 0.1928 -0.1774 -0.1946 -0.2157 -0.0734 ...

> sapply(df_prop, class)
         activ        protein         cancer           role        oncogen           loss        missens         recurr 
     "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric" 
        driver            cbl           gain        neutral      polymorph       deleteri            loh         switch 
     "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric"      "numeric" 
       passeng      inconclus heterozygosity          q249e 
     "numeric"      "numeric"      "numeric"      "numeric" 

> length(df_prop$passeng)
[1] 204
> length(df_prop$neutral)
[1] 204
> length(df_prop$driver)
[1] 207
> dput(df_prop[c("passeng", "neutral", "driver")])
structure(list(passeng = c(0.452785223722458, -0.349059224128723, 
0.223233446478844, -0.285723477602005, -0.0530807785689831, -0.112091585993767, 
0.0916753336787224, -0.505712330341339, -0.0289060920476913, 
-0.0842016264796257, 0.338186889886856, 0.586610317230225, 0.216203600168228, 
0.410553187131882, 0.0717814415693283, -0.0429450906813145, -0.0296403076499701, 
-0.23951618373394, 0.159736976027489, -0.414268016815186, 0.0648640096187592, 
-0.0192434135824442, -0.0520854219794273, 0.133157446980476, 
-0.00781008694320917, 0.0803053453564644, 0.04029206559062, -0.227307245135307, 
-0.34715148806572, 0.0180112048983574, 0.0419463403522968, -0.287112087011337, 
-0.103216387331486, -0.00813597533851862, -0.473377019166946, 
0.02095066010952, -0.0118085974827409, 0.0805344358086586, -0.0890048146247864, 
-0.0509019605815411, 0.0337137281894684, -0.140259340405464, 
-0.164335578680038, 0.0143457390367985, -0.421713650226593, -0.350066483020782, 
0.256413668394089, -0.262221038341522, 0.125508412718773, -0.1669010668993, 
-0.323957771062851, 0.121560901403427, 0.0398254878818989, -0.127609387040138, 
-0.348305493593216, -0.59373140335083, -0.43903249502182, 0.018520962446928, 
0.201807394623756, -0.444083839654922, 0.200975254178047, -0.301672697067261, 
0.230098724365234, 0.0907209143042564, 0.0885164812207222, 0.0177833493798971, 
-0.0124702183529735, -0.0641361474990845, -0.0831363871693611, 
-0.19027952849865, -0.166728913784027, 0.0293176043778658, 0.142488345503807, 
0.319564342498779, 0.0564890131354332, 0.0332652218639851, 0.0741571933031082, 
-0.0815279185771942, 0.0147021086886525, 0.077141061425209, -0.177572771906853, 
0.0499499812722206, -0.0831519737839699, 0.112121917307377, -0.103135667741299, 
-0.353338032960892, 0.15715280175209, -0.125472351908684, -0.144316121935844, 
-0.223944634199142, 0.0473198145627975, -0.285173535346985, -0.091559074819088, 
-0.23955462872982, -0.135925456881523, 0.106332272291183, 0.3387231528759, 
-0.230065390467644, -0.0370972417294979, -0.267686247825623, 
0.0271094776690006, -0.263466387987137, -0.124173454940319, -0.129989266395569, 
0.0639095827937126, 0.0804392695426941, -0.205364063382149, 0.34429532289505, 
-0.239175975322723, 0.521911144256592, -0.0506611131131649, 0.0372519791126251, 
-0.110514439642429, 0.0399324893951416, -0.0326474010944366, 
0.0534966289997101, -0.336249321699142, 0.0687438398599625, -0.0149638978764415, 
-0.079196035861969, 0.0412308536469936, -0.168989613652229, 0.426938116550446, 
0.108011208474636, 0.356941521167755, -0.35343012213707, 0.208558425307274, 
-0.0620005242526531, 0.13456092774868, -0.214266702532768, -0.314923346042633, 
-0.0311665218323469, -0.192426383495331, 0.103004567325115, -0.119352847337723, 
0.0841932892799377, -0.0218736603856087, -0.178017675876617, 
-0.124427333474159, 0.233909919857979, 0.0559673868119717, -0.104320652782917, 
0.296732783317566, -0.19652085006237, 0.28268176317215, 0.118357747793198, 
0.324692904949188, 0.173546448349953, 0.119432643055916, -0.0791224911808968, 
0.119982831180096, -0.141497865319252, -0.191946685314178, 0.154124990105629, 
0.185841098427773, -0.147911578416824, 0.408693969249725, 0.151209264993668, 
-0.432886987924576, 0.00650644721463323, -0.315581798553467, 
-0.247532770037651, 0.143373981118202, -0.364778310060501, 0.226706951856613, 
0.0187635440379381, -0.0128085305914283, -0.116108402609825, 
-0.203655496239662, -0.063552051782608, 0.0922449454665184, -0.371555089950562, 
-0.143712520599365, 0.323709845542908, -0.0827256366610527, 0.10759025067091, 
0.342874735593796, -0.266680926084518, 0.24025596678257, 0.35177743434906, 
0.00122027634643018, 0.320188760757446, 0.180638343095779, 0.204436093568802, 
-0.049614429473877, -0.0895709544420242, -0.0814719721674919, 
0.000497184810228646, 0.15266053378582, 0.243941411375999, 0.0695823654532433, 
-0.0984447300434113, 0.156076744198799, 0.40799942612648, -0.359382539987564, 
-0.0958247110247612, -0.063414603471756, -0.492347091436386, 
-0.212932005524635, -0.399490386247635, 0.452785223722458, -0.349059224128723, 
0.223233446478844, -0.285723477602005), neutral = c(0.0624283887445927, 
0.106615483760834, -0.242450177669525, -0.00875413231551647, 
-0.0607167445123196, -0.0874784588813782, 0.0159694887697697, 
-0.310035288333893, -0.470642864704132, 0.312223583459854, -0.0133906025439501, 
0.456694394350052, 0.327305197715759, -0.0492987744510174, -0.327871382236481, 
0.0123024489730597, -0.112976022064686, -0.183681637048721, 0.0786364153027534, 
-0.0556268356740475, 0.0593749359250069, 0.308130115270615, 0.0545936934649944, 
0.0112099116668105, 0.195658937096596, -0.0926103219389915, 0.131353974342346, 
0.36189866065979, -0.310230076313019, -0.0959832593798637, 0.0129279075190425, 
0.0170739497989416, -0.212557435035706, -0.10607548803091, 0.0198365785181522, 
-0.0790213569998741, 0.233813554048538, 0.0603582486510277, 0.0574430525302887, 
-0.0025249389000237, 0.178253039717674, -0.161745145916939, -0.0651656538248062, 
0.0898096263408661, -0.199210107326508, 0.345266789197922, -0.0608342587947845, 
-0.0240304097533226, -0.059606347233057, 0.237234279513359, -0.182934284210205, 
-0.0805316418409348, 0.477729558944702, 0.355416506528854, -0.195008412003517, 
-0.285221040248871, -0.275740891695023, -0.0590328797698021, 
0.00807524751871824, -0.181720346212387, 0.133480831980705, -0.0923505499958992, 
0.319016247987747, 0.310231000185013, 0.0212804675102234, -0.158257618546486, 
-0.00906388554722071, 0.133870497345924, 0.163518846035004, 0.159345477819443, 
0.00162855989765376, -0.244596600532532, 0.265527069568634, -0.0766861364245415, 
0.071528285741806, 0.200394779443741, -0.0659522116184235, -0.0894035324454308, 
0.386227011680603, 0.155652150511742, 0.206601455807686, -0.34688338637352, 
0.103099264204502, 0.336126208305359, -0.109791465103626, 0.025560649111867, 
0.18004846572876, 0.0455960370600224, 0.129409417510033, -0.0663190484046936, 
-0.0694380551576614, 0.269877940416336, 0.123965159058571, 0.208219081163406, 
-0.0259098093956709, 0.0244570504873991, -0.0531765818595886, 
-0.224155947566032, -0.115240715444088, 0.0962978675961494, 0.157494246959686, 
0.00240525603294373, -0.0600106082856655, 0.167411848902702, 
-0.00585554260760546, 0.0355127118527889, -0.196092844009399, 
-0.0188772100955248, -0.151142120361328, -0.200211212038994, 
-0.0215719062834978, 0.0169646516442299, -0.16918058693409, -0.0534995049238205, 
0.143689811229706, 0.0359412282705307, 0.279378980398178, 0.258504390716553, 
-0.074554406106472, 0.335559964179993, 0.263022631406784, 0.197986051440239, 
-0.138966783881187, 0.195296406745911, 0.143159613013268, -0.148128971457481, 
0.3902488052845, -0.345333695411682, -0.134910404682159, 0.135866537690163, 
0.278762727975845, 0.118465282022953, -0.22791101038456, -0.154258042573929, 
-0.152354970574379, 0.0967835634946823, 0.476795643568039, -0.575522124767303, 
-0.1163110435009, 0.173384621739388, -0.249152660369873, -0.110836043953896, 
-0.120327040553093, 0.123326189815998, 0.036122415214777, 0.0511444658041, 
0.101496443152428, 0.142479866743088, 0.0739700049161911, -0.101869978010654, 
0.0706672668457031, -0.0612174309790134, 0.208535611629486, 0.0153503911569715, 
-0.121934145689011, -0.0994135960936546, 0.301655441522598, -0.117937028408051, 
-0.467048764228821, -0.126288637518883, -0.263451159000397, 0.164172038435936, 
0.365282714366913, 0.216561645269394, 0.185734942555428, 0.199943736195564, 
0.126512348651886, -0.072352223098278, 0.129932269454002, 0.309069633483887, 
0.000678401032928377, -0.00318608805537224, 0.136844977736473, 
0.366614729166031, -0.326217412948608, 0.0876872763037682, -0.0637753307819366, 
0.112328112125397, -0.392527550458908, 0.0157560463994741, 0.0637902021408081, 
-0.15483346581459, 0.0630035400390625, 0.167358994483948, 0.226734787225723, 
0.0888303220272064, 0.0440737493336201, 0.107901841402054, -0.115406967699528, 
-0.0672288686037064, -0.0101721612736583, -0.110640466213226, 
-0.24146357178688, 0.113892689347267, 0.108142912387848, -0.239095509052277, 
-0.0326027497649193, 0.144274324178696, -0.0831330195069313, 
-0.0282934606075287, 0.0624283887445927, 0.106615483760834, -0.242450177669525, 
-0.00875413231551647), driver = c(0.192841440439224, -0.177443191409111, 
-0.194590926170349, -0.215662553906441, -0.073422372341156, -0.249199375510216, 
0.336783885955811, -0.247152045369148, 0.0759363397955894, 0.202224016189575, 
0.0579937845468521, -0.0315181687474251, -0.268824219703674, 
0.163264974951744, 0.320090681314468, 0.0288974922150373, 0.00578439189121127, 
-0.238630563020706, 0.263456761837006, -0.326677918434143, 0.0100676929578185, 
0.186660930514336, 0.0529752001166344, 0.172556579113007, 0.0344753190875053, 
-0.0375318937003613, 0.090083159506321, -0.202253371477127, -0.15420438349247, 
-0.0356156565248966, 0.196105360984802, -0.0992875695228577, 
-0.0626049414277077, -0.0435837954282761, -0.12100450694561, 
-0.010941019281745, 0.27052915096283, -0.0454284884035587, -0.269113779067993, 
-0.065261498093605, 0.180837854743004, 0.0523905120790005, 0.147859752178192, 
-0.0145671898499131, -0.438302397727966, -0.237480729818344, 
-0.13623084127903, 0.0325649604201317, -0.0994360595941544, -0.2902792096138, 
-0.437496393918991, -0.0240569356828928, 0.170194000005722, -0.105672776699066, 
-0.0963042005896568, -0.329953551292419, -0.389930844306946, 
-0.0327115058898926, -0.233221232891083, -0.0197642371058464, 
0.273058503866196, -0.389816999435425, 0.00940189696848392, -0.00786798354238272, 
0.172658368945122, 0.0880637839436531, 0.022097198292613, 0.129856511950493, 
0.180789142847061, -0.260635018348694, 0.00472282106056809, 0.107697121798992, 
0.106692224740982, 0.194839581847191, 0.238379791378975, 0.00421210564672947, 
-0.169722050428391, -0.131127566099167, -0.114339262247086, -0.0567750222980976, 
-0.129207447171211, 0.0325682610273361, -0.0426204539835453, 
0.285478800535202, 0.0624793395400047, -0.329177767038345, -0.183537155389786, 
0.0478714108467102, -0.527256846427917, 0.208344429731369, -0.223630920052528, 
-0.189286127686501, 0.138937622308731, 0.0905347689986229, -0.422364205121994, 
-0.14398404955864, -0.00858693942427635, -0.0884147360920906, 
0.226146027445793, -0.210005864500999, 0.0122118107974529, -0.268835186958313, 
0.0258086826652288, -0.0687210634350777, -0.0857537835836411, 
-0.135309383273125, -0.105474129319191, 0.293376386165619, -0.136220842599869, 
-0.0430038720369339, 0.110145010054111, 0.408281266689301, -0.198951378464699, 
-0.123419873416424, 0.0606197938323021, -0.0718433782458305, 
0.237005949020386, 0.0853797197341919, -0.0541917011141777, -0.00938241742551327, 
0.0353678315877914, -0.230596140027046, 0.110361091792583, 0.161412462592125, 
0.085545040667057, -0.12790310382843, -0.13336968421936, 0.17795641720295, 
0.0733387023210526, -0.308348536491394, -0.181677877902985, 0.101970627903938, 
0.0291164517402649, -0.0242572482675314, -0.236937135457993, 
-0.0996431559324265, 0.0395178869366646, -0.315638035535812, 
0.133494392037392, 0.162245228886604, 0.173758044838905, -0.0769962817430496, 
0.0964652448892593, -0.182265087962151, 0.0921082720160484, 0.153241410851479, 
0.362468242645264, 0.306828439235687, 0.0799067765474319, 0.0426596254110336, 
0.303493797779083, -0.165668562054634, -0.0794251933693886, 0.327983409166336, 
-0.0429684445261955, -0.0296640377491713, 0.0362571738660336, 
-0.0495377406477928, -0.0970798581838608, -0.0806222558021545, 
-0.452878385782242, -0.161120310425758, 0.233113989233971, -0.190250247716904, 
-0.0330471470952034, 0.302920013666153, 0.14268185198307, -0.114068612456322, 
-0.31039759516716, -0.225921854376793, 0.205708786845207, -0.319309294223785, 
-0.308616161346436, 0.168272659182549, -0.0735112801194191, 0.112985752522945, 
0.0841426774859428, -0.363907188177109, -0.0197736043483019, 
0.0447185151278973, -0.00954608619213104, 0.100676394999027, 
0.143523827195168, -0.07918681204319, -0.109777048230171, -0.17021943628788, 
-0.0855320245027542, -0.144370004534721, -0.0573471039533615, 
-0.0151970209553838, 0.233068540692329, -0.198467314243317, 0.154547318816185, 
0.332190752029419, -0.402606934309006, 0.1740802526474, 0.194449007511139, 
0.115612171590328, 0.266910642385483, -0.311915367841721, 0.192841440439224, 
-0.177443191409111, -0.194590926170349, -0.215662553906441, -0.073422372341156, 
-0.249199375510216, 0.336783885955811)), .Names = c("passeng", 
"neutral", "driver"), row.names = c(NA, -200L), class = "data.frame")

0 个答案:

没有答案