0

I have a data frame named Ash having these 4 columns

Cat     Qty     Rev     Margin    
A        2    100    2%          
B        3    200    3%        
C        4    300    4%         
D        5    400    5%         

I need to merge this with data to another data frame named as Test which has three parts(A,B and C). So I only want to merge Ash data frame with part A in Test and not to the entire data frame including part B and part C.If I use merge it will apply to all the data frame Test.

How to use loop by using coloumn and row specific numbers to fill the data in test using category as common variable. I have used numbers for referencing. 1,2,3,4 in columns refer to their position. 1,2,3,4 under X.no is for row referencing. Part A(Overall) 1 2 3 4

X.no       Cat       TotalQty       TotalRev       TotalMargin  
1           A      
2           B    
3           C    
4           D    

For Web Part B

Cat  
A  
B  
C  
D  

For Non-Web

Part C

Cat  
A    
B    
C     
D     
nicola
  • 24,005
  • 3
  • 35
  • 56
Ashish
  • 73
  • 6
  • I don't understand the three parts. Plus it would be helpful to have the second data.frame and the desired output. You can paste the result of `dput` on each of your df so that it's easier to [reproduce](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) your problem. – Vincent Bonhomme Apr 16 '16 at 11:36
  • hello Vincent I want a report which has three parts. Part A has to be filled with Ash data frame only. Part B and Part C has to be filled with some other data frame. Hence I just need to loop and fill numbers for part A i.e. test data frame – Ashish Apr 16 '16 at 11:47
  • still unclear to me and results of `dput` would be useful anyway if one need them to help ;-) – Vincent Bonhomme Apr 16 '16 at 11:48
  • 1
    You can filter during merge: `merge(Ash, Test[(Test$Cat=='A'),], by='Cat')` – Parfait Apr 16 '16 at 13:17
  • See test is my data frame where Cat is repeated thrice so I have broken them in part A B and C. If I use merge it will paste all the data to entire test data frame. I just want it to copy in part A. So instead I want to loop using columns and rows as a reference to paste the data from Ash to Test. – Ashish Apr 17 '16 at 12:40

0 Answers0