I'm looking at census data for Ontario, Canada and there are columns that have the same column name (they have the same name because they represent different subdivisions of the census regions). I want to sum row-wise for any columns that have the same column name but have run into trouble. In my sample data there are only duplicate column names, but in the actual data there are several columns with the same name. Is there a vectorized way in R to do this?
TORONTO HALTON PEEL YORK BRANT HALDIMAND-NORFOLK HAMILTON MUSKOKA NIAGARA
20855 4011 11178 8138 996 739 3835 305 2923
23281 3997 11770 8417 961 684 4095 343 2970
24130 3900 11810 8306 972 732 4168 334 2985
TORONTO HALTON PEEL YORK BRANT HALDIMAND-NORFOLK HAMILTON MUSKOKA NIAGARA
39924 7863 21415 15714 1947 1428 7320 646 5675
44357 7820 22340 16261 1861 1369 7755 697 5775
46016 7679 22577 16260 1971 1447 7883 717 5868
I attempted it with ifelse statement with no luck. Something like this pseudo-code:
# where i is the column name
for every column with name i(sum rows of each column with name == i)
Would appreciate any guidance!!
Aucun commentaire:
Enregistrer un commentaire