I am new to both StackOverflow and R stats, so please bear with me. I have a lot of experience with coding in SAS, but am trying to learn R. I commonly use SAS and R to transform large datasets, I have a species by study site matrix as follows:
Species Status Role Site1 Site2 Site3...Site25 A_a S P 0 0 0 1 A_b SO X 1 25 0 0 B_a S P 0 2 1 1 B_b S X 0 1 0 0 ...
I would like to transform this table and create 2 new variables called "Site" and "Count" based on the site variable names and the count data within each site:
Species Status Role Site Count A_a S P Site1 0 A_a S P Site2 0 A_a S P Site3 0 A_a S P Site25 1 A_b SO X Site1 1 A_b SO X Site2 25 A_b SO X Site3 0 A_b SO X Site25 0 ... B_b S X Site25 0
I think that this may be beyond the simple t() function, and have looked into the packages reshape and reshape2, but am kind of lost as to how to proceed. Would anyone have had a situation like this and could lend a hand with coding? Thanks, JimH