Reputation: 1
I am trying to use R studio to combine columns in a matrix of microbial data. When I import my .csv into R in looks like:
species.1 taxa.1 species.2 another.1 taxa.2
ind1 2 4 2 4 3
ind2 4 2 6 3 0
And I want it to look like:
species taxa another
ind1 4 7 4
ind2 10 2 3
I've seen different codes that allow me to do this on a small scale, but I need something to help me reconcile this for a large data set (54x521).
Upvotes: 0
Views: 87
Reputation: 79208
lets say your matrix is called dt, you could do:
Using base R, you could do
sapply(split.default(data.frame(dt),sub("\\..*","",colnames(dt))),rowSums)
another species taxa
ind1 4 4 7
ind2 3 10 2
Upvotes: 1