r - Comparing the difference in values between two data frames -


I have two different frames, each 3 columns: 'name' 'amount' 'year' '

I want to be able to identify common ???? Name ?? Calculate the difference between two data amount of the variable frame and each For example:

  name years ago by James 2010 934706 -2340 Rory 2010 869691 240576 Suzanne 2010 651 674 37 765 Felicity 2010 386 115 -512,275 Olivier 2010 382388-278,410   

So far I have:

  common_order & lt; - Common variables among colonames (D1), colnames (D2)) two dataframes d2 = d2 [, common_order] #variables #finds D2D1D1 = D1 [, Common_Edder] D3 = 2 data frames together in D2 in the same order as RBID (D1, D2) D4 = Integrated (D3 [, 1: 3], list (D3 $ name), (D 2-d1)) This line of code is not working because the data frames are not of the same size   

Is there any way to do this? Structure (list (year = C (1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950), 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950), name = C ("Linda", "Mary", "Patricia", "Barbara", "Susan", "Nancy", " Deborah "," Sandra "," Carol "," Kathleen "," Sharon "," Karen "," Donna "," Brenda "," Margaret "," Dien "," Pamel a "," Janet "," Shirley "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F" F "," F "," F "," F "," F "," F "," F "," F "," F "," F "," F "), zodiac = c (80412L, 65443L, 47920L, 41560L, 38019L, 29618L, 29074L, 28 885L, 26159L, 25693L, 24612L, 24137L, 21633L, 20797L, 18111L, 17616L, 16201L, 16189L, 15876L, 15593L)), .Names = C ( "old", "name", "gender", "amount"), DP (Head (D2, 20)) structure (list (year = C (2010, 2010, 2010, 2010, 2010, 2010, 2010) 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010), name = c ("Isabella", "Sophia", "Emma", "Olivia", " Eva "," Amelie "," Abigail "," Madison "," Chloe "," MIA "," Edison "," Elizabeth "," Ella "," F "," F "," F "," F " , "Natalie", "Samantha", "Alexis", "Lily", "Grace", "Halley", "Elisa" "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F" 'F', 'F', 'F'), the amount = c (22822L, 20566L, 17277L, 16959L, 15382L, 14235L, 14208L, 13133L, 11715L, 10599L, 10302L, 10209L, 9844L, 8746 L, 8378 L, 8222 L, 7947 L, 7651 L, 69 9 L, 6963 L). Name = C ("year", "name", "gender", "zodiac"), line.Name = C (NA, 20L) Class = "data.frame")

:

  transform (D1, D2 [, - 3], = 'Name'), difference = sum. X-amount.y) [, - c (4,6)] # name year.x gender year. Difference # 1 Carroll 1950 F 2010 5593 # 2 Caroline 1950 F 2010-116 # 3 Karen 1950 F 2010 1315 # 4 Kathleen 1950 F 2010 11485 # 5 Mary 1950 F 2010 57 792 # 6 Patricia 1950 F 2010 40 9 7 # 7 Sandra 1950 F 2010 18286 # 8 Sharon 1950 F 2010 14403 # 9 Shirley 1950 F 2010 5574 # 10 Susan 1950 F 2010 30,072 < / Code>  

data

change d2 some overlapping name

  set.seed (24) d2 $ name & lt; - Sample (c (d1 $ name, d2 $ name), 20, change = FALSE)    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -