2

所以我有以下列,我需要创建一个新列,它是它们两者之间的差异,U-Mean。但是当我这样做时,我会得到一个与“U”相同的新列

这是两列的输入

意思是:

c(1.55253151317529e+73, 5.42630341565764e+72, 1.22360008978886e+73, 
1.44754562839592e+73, 6.15300952473276e+73, 3.92849083208013e+72, 
1.39907822366272e+73, 2.970729344696e+71, 1.2320012180046e+71, 
1.10765949579834e+72, 4.21312101733708e+70, 5.13240241235222e+72, 
1.38229078824807e+68, 3.62297632538558e+68, 4.97331594982401e+73, 
3.6320637537423e+71, 2.14299728784724e+69, 7.76102613008456e+72, 
2.54479231787974e+73, 1.2551256832845e+69, 1.48931149067776e+74, 
1.43341267107345e+70, 4.20074897519876e+70, 5.10699623700277e+71, 
3.57000197272229e+70, 3.33342400641716e+69, 7.01251747522522e+71, 
3.14452082179796e+70, 6.41657409256216e+72, 8.3470989604027e+74, 
8.14062942045136e+72, 2.42755708858872e+70, 1.01628065622882e+71, 
1.83846717218483e+72, 1.12267076186172e+70, 4.11806255937942e+69, 
6.29839174284616e+69, 1.4326205924077e+71, 3.29376960704195e+71, 
1.91951007014028e+68, 2.48953274835279e+69, 4.7250404611893e+73, 
1.3188288351312e+67, 1.19431230433792e+70, 9.997056482597e+69, 
9.6958762321997e+69, 1.33691693237741e+69, 6.48697251345129e+70, 
2.21843437635598e+73, 1.60661616551939e+73, 7.12479122077463e+69, 
2.58201096048811e+69, 1.25512730017043e+71, 4.58689558053565e+71, 
1.30350485529305e+70, 2.23357150130185e+69, 2.90852294755605e+70, 
6.45275020406759e+70, 3.31939435138082e+67, 2.36170408236555e+72, 
5.3542701058383e+71, 1.17788187628994e+74, 3.89751907340584e+73, 
2.41420070426009e+73, 4.82936778869107e+73, 7.59256110238055e+73, 
1.26139096660225e+74, 4.43714148727955e+72, 1.70491087685728e+73, 
2.7754730346649e+71, 3.13542074129113e+74, 5.31506649544345e+74, 
8.63562922676285e+72, 1.50746701657928e+73, 3.16188888940025e+73, 
2.45980350289092e+71, 6.2927904089503e+69, 6.50707963215015e+72, 
7.05248011964843e+66, 1.24434480077796e+74, 1.04056675322264e+73, 
1.22286152625816e+73, 6.05031234067607e+71, 4.90660383403135e+71, 
1.22950366003675e+75, 3.95977914666399e+73, 4.5597290479942e+71, 
5.77344333696613e+70, 1.59325176016623e+73, 1.52170375878966e+69, 
1.07082850186347e+75, 3.01792959492489e+73, 4.74230561875729e+72, 
1.05529932338963e+73, 6.61876366768282e+73, 1.13579185144396e+67, 
6.34351019214156e+68, 4.4245912165946e+73, 2.07901436945324e+69, 
2.68163917245049e+67, 1.16115891626683e+70, 1.40026116347209e+69, 
4.78896128432115e+67, 1.21813692655002e+67, 5.03393144593665e+69, 
1.27191462675911e+73, 2.67405599247843e+68, 1.36858934333613e+67, 
1.14741393362245e+67, 8.21705628639157e+69, 5.01121920253856e+72, 
1.57101362708694e+71, 8.44981977226733e+69, 1.61663906886666e+68, 
9.74236192350587e+68, 1.27629145918939e+67, 1.32593700681877e+73, 
1.42900570433071e+68, 2.34601789998151e+72, 4.12008794836411e+70, 
2.54760675803449e+68, 4.16411042284085e+69, 4.28878339068495e+69, 
3.13004759063901e+72, 1.6976870599962e+73, 1.20945741774772e+69, 
8.32897792637601e+73, 4.21033327366785e+66, 7.44803839780427e+70, 
8.53140919764391e+67, 8.61996331775236e+70, 7.91580174829875e+73, 
3.43671560100175e+70, 1.13740093576237e+73, 2.86393222400101e+73, 
1.38927103020111e+71, 6.41904918894624e+66, 1.98809054116388e+73, 
6.03145873926411e+69, 1.10404721581918e+72, 9.54172815719435e+71, 
3.68340697664094e+69, 5.2964730621829e+72, 3.13428596929331e+73, 
1.06454842923809e+67, 2.1465036540392e+71, 3.22914916959531e+70, 
1.84745489009172e+68, 1.97157955079142e+70, 4.84713745445637e+68, 
1.42114921669825e+70, 2.86156238434447e+69, 9.20357415988203e+72, 
2.86687265452894e+72, 1.45200933859367e+67, 7.42191773946482e+71, 
3.61609702066932e+71, 5.33292940379054e+74, 1.74879776831424e+76, 
1.21448850853267e+67, 5.52808331172991e+67, 1.02958447122125e+71, 
4.03292281193831e+70, 8.21456335193046e+69, 1.97298748038642e+73, 
7.72160789630034e+68, 1.02663027760963e+75, 2.15496567683224e+69, 
1.314681768403e+71, 2.25766632947779e+67, 1.38617730664941e+67, 
8.96803335586374e+70, 4.70329240619768e+73, 7.15373697267349e+67, 
2.36264621569539e+73, 5.83131176368268e+71, 2.89004223741167e+73, 
2.343113114565e+70, 8.66802020441005e+69, 8.90238408835327e+69, 
3.39397828772853e+73, 5.12937416296374e+67, 9.3842101189779e+67, 
4.344892152397e+73, 2.20102431548773e+71, 1.91222939237993e+72, 
1.06782013187912e+70, 2.61007517238819e+73, 3.79351222471497e+74, 
2.69216026612086e+67, 4.44687958307426e+72, 1.28741422135471e+68, 
6.90206201819735e+69, 5.68997095168854e+68, 3.41843282885697e+68, 
5.44134351669776e+72, 1.4433560772192e+69, 3.21987897015245e+66, 
2.46075465810233e+67, 1.72538778018638e+70, 6.11488493515457e+68, 
3.68925197527588e+67, 5.41191150506896e+73, 7.46999162938597e+66, 
7.20780967196527e+67, 7.20343531913118e+67, 2.98910676719826e+67, 
2.18962623962568e+67, 2.1891249653041e+68, 4.61336450499246e+73, 
2.58648857054187e+66, 2.39460304482973e+69, 1.87138566285836e+70, 
1.13871660834551e+67, 1.61583274438271e+67, 4.11576373651183e+69, 
2.86623598187836e+67, 6.90526523880702e+67, 2.55745321138324e+67, 
2.68439195070092e+66, 1.45224050837299e+73, 2.23701864125269e+71, 
3.41264972441643e+67, 1.87616755084226e+69, 1.17169378451702e+70, 
4.69909991723406e+72, 2.68669860166646e+70, 5.63395185708018e+75, 
1.58639259920664e+68, 2.05530948589365e+68, 1.35232612890447e+73, 
2.48599712116031e+74, 6.36120248300978e+71, 1.56205473140127e+73, 
1.84237627764013e+67, 4.93129954884014e+67, 4.25605834043945e+67, 
1.81468137845717e+68, 3.45427024144924e+67, 1.22040491778145e+67, 
1.85799811573777e+67, 2.71540773689855e+67, 3.05735707496693e+67, 
3.34021946938125e+67, 5.02754342786926e+66, 2.00494415121282e+69, 
2.57858400272962e+66, 1.17884901196427e+67, 3.41604686431786e+67, 
3.33582168187927e+67, 9.37185705072798e+66, 2.86216250401564e+69, 
2.73458639988219e+68, 3.61407943237885e+66, 3.4833678745653e+66, 
3.40074134685724e+70, 9.97013795364857e+65, 2.03464364972619e+67, 
2.66223803316952e+67, 1.67488632878599e+67, 6.76531412122325e+70, 
3.00507033132355e+69, 5.66737809244866e+67, 1.16858394312542e+68, 
8.46330533849227e+69, 1.65219529118728e+67, 7.62289229687017e+66, 
2.06922291435525e+68, 4.06076448774227e+67, 4.84954681636896e+68, 
1.58600874876413e+67, 6.63318787751275e+67, 1.17267956406703e+67, 
1.54485566304424e+67, 3.04308255050303e+68, 8.73960809932228e+72, 
1.3810988929807e+68, 2.25400751233207e+68, 1.14001423691631e+71, 
2.18111869866766e+67, 2.06554297108457e+67, 1.21377212930861e+67, 
4.22715578426216e+67, 2.47286745428055e+67, 4.78947920754389e+66, 
3.02561922183011e+69, 2.60132336410034e+67, 4.51668719750693e+66, 
2.25407741981751e+67, 3.55406978202292e+66, 8.41474948867401e+66, 
1.27453263042903e+68, 8.15330782629354e+72, 1.65926825134963e+67, 
6.22157703771182e+67, 8.07326973696837e+66, 1.33497011066024e+67, 
9.24625999131284e+66, 2.923510563377e+68, 3.31899790958802e+68, 
6.3902998070815e+69, 6.811106410846e+73, 1.16335465124e+69, 1.89871767886208e+69, 
2.36913600391179e+68, 1.01930222144775e+67, 6.59709111072695e+66, 
8.30284489125039e+68, 2.87250184621952e+66, 6.03833846340568e+67, 
1.6703492623521e+68, 1.8237570149392e+68, 9.49914540906518e+66, 
2.54243104299361e+66, 2.13205327973108e+68, 7.68922546083881e+66, 
8.0915362789067e+66, 2.42414117775254e+70, 4.92613554090206e+71, 
2.90187402256851e+67, 4.24101097142233e+69, 4.74968866816986e+66, 
1.19882028580387e+70, 2.66796229098593e+68, 4.35312710432633e+66, 
1.65188505137905e+73, 1.03788763390688e+71, 1.53603700709953e+67, 
3.0897209336982e+66, 1.46849418739811e+67, 8.64193350728012e+67, 
4.18198014529839e+68, 1.69319380061928e+67, 6.71129234117025e+67, 
5.00995352252452e+67, 1.37936785235067e+66, 1.14605964233339e+67, 
1.62810174186632e+67, 3.37551613693693e+69, 1.51309361000095e+70, 
1.01341021888531e+69, 6.56235495053029e+66, 1.1154495782132e+74, 
5.06184647608577e+66, 2.68774549234988e+69, 6.42380674408293e+66, 
3.30121132618869e+69, 3.10815348868232e+69, 1.88925012010279e+73, 
6.36211977449932e+72, 1.74215905427736e+67, 7.03536459960573e+71, 
1.56823257809068e+67, 3.78773213003662e+66, 2.98424943060575e+66, 
1.24524123152695e+67, 1.14033972050617e+72, 2.01517008253518e+71, 
3.05285108373863e+67, 2.00736437837746e+67, 2.58182217604794e+66, 
1.11425393232359e+68, 4.32490063527912e+67, 5.7735929460136e+74, 
1.1237358299657e+68, 2.04981882548133e+67, 4.43009491874767e+70, 
2.67851262386052e+71, 9.75119213344488e+74, 8.33184925820538e+72, 
2.40168352996766e+68, 1.00333846406543e+69, 1.37107411696348e+68, 
1.64725432285334e+69, 5.78095430099518e+67, 3.74169507882638e+69, 
1.21904290547014e+70, 4.08523373255014e+67, 1.41796494077346e+68, 
2.44121274692289e+68, 1.71342670106452e+68, 4.05385372416494e+66, 
6.81167807145163e+66, 3.28036950271773e+71, 2.17074652127888e+68, 
4.60255091188396e+72, 2.02258545161256e+68, 5.12120242263114e+69, 
1.3735994698205e+74, 1.87706860326199e+68, 1.00419546257911e+71, 
5.94472624834099e+68, 2.37940603433543e+70, 3.04427058528496e+68, 
1.8961157778709e+69, 5.22115825176672e+66, 1.39667183775905e+68, 
4.62330429546154e+67, 3.77149602737348e+68, 3.03457602014982e+68, 
2.249352756211e+68, 5.06263395728767e+69, 1.45725589701442e+68, 
9.92150824636926e+67, 2.69885324593366e+65, 2.73179190644663e+69, 
8.8705666844999e+69, 9.85296942780477e+68, 9.54762636803144e+67, 
2.21055430887402e+67, 1.31098468397055e+67, 6.6797183163169e+67, 
3.344964152527e+66, 1.53469020445677e+71, 3.41923701185917e+70)

你:

c(1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 1e+82, 
1e+82)
4

2 回答 2

6

这里唯一的问题是你的Mean列比U列小大约 10 个数量级,所以当你得到差异时,它与 没有区别U

df$diff <- df$U - df$Mean
df$diff2 <- df$Mean - df$U
# > head(df)
# Mean     U  diff  diff2
# 1 1.552532e+73 1e+82 1e+82 -1e+82
# 2 5.426303e+72 1e+82 1e+82 -1e+82
# 3 1.223600e+73 1e+82 1e+82 -1e+82
# 4 1.447546e+73 1e+82 1e+82 -1e+82
# 5 6.153010e+73 1e+82 1e+82 -1e+82
# 6 3.928491e+72 1e+82 1e+82 -1e+82

所以我不确定你是否期望你的数据会有所不同,但是对于这些数量级的数字,它们之间的差异并不会真正有意义。

于 2013-03-16T00:34:15.430 回答
2

假设您 data.frame 包含体积 U 和平均值:

df.res <- transform(df, new.col = U - mean)

编辑我最初的答案很简短,因为从智能手机回复不方便 - 只是认为快速回复可以解决您的问题。

现在稍微解释一下。Transform 是在 data.frames 内操作的最有用的功能之一 - 请注意,从你的问题中不清楚列是否在同一个 data.frame 中 - 因为它允许从列之间的几乎任何操作创建列,或单个列的转换。例如,您可以创建一个 U 的日志

df.res <- transform(df, logU = log(U)) 

或更优雅地输出对数转换 U 后的最终差异:

df.res <- transform(df, new.col = log(U) - mean)

可能性几乎是无穷无尽的。

于 2013-03-16T00:33:41.387 回答