R-Stats: Add two arrays using factors -


starting 2 files follows:

test1.r

crop, value coconut, 12300 amaranthus, 123 cowpea, 100 brinjal, 210 coconut, 500 brinjal, 10 coconut, 1000 cowpea, 105 

test2.r

crop, value rubber, 10 cardamom, 22 amaranthus,  12 garcinia, 10 brinjal, 10 coconut, 1000 brinjal, 25   > d1 = read.csv("test1.r") > d2 = read.csv("test2.r") > sum1 = tapply(d1$value,d1$crop,sum) > sum2 = tapply(d2$value,d2$crop,sum) > sum1  amaranthus    brinjal    coconut     cowpea         123        220      13800        205  > sum2 amaranthus    brinjal   cardamom    coconut   garcinia     rubber          12         35         22       1000         10         10  

i merge sum1 , sum2 single array applying operators such 'sum' value, if respective values if factor exists in both files (such amaranthus, brinjal , coconut), or inserting name-value pair if exists in 1 file. in short, output should follows (transposed convenience, , assuming 'sum' operator):

amaranthus  135 brinjal  255 cardamom 22 coconut 14800 cowpea 205 garcinia 10 rubber 10 

tia help,

s1b


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -