I have a dataframe like this:
df <- structure(list(A = c(2, 3, 1), B = c(3, 2, 1), C = c(4, 5, 1),
D = c(4, 4, 1), Genus = c("Ensifer", "Ensifer", "Ensifer"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L))
A B C D Genus
<dbl> <dbl> <dbl> <dbl> <chr>
1 2 3 4 4 Ensifer
2 3 2 5 4 Ensifer
3 1 1 1 1 Ensifer
In this dataframe I have five columns, in which four columns have values while fifth column have names and the same name is repeated multiple times but I want that the name Ensifer
become one and all the values add up and come in a single row just like this
A B C D Genus
<dbl> <dbl> <dbl> <dbl> <chr>
1 6 6 10 9 Ensifer
I want to do this in R as data is too long
I have tried this code but it is taking too long
count <- read.csv("count_data.csv", header=T)
shl <- aggregate(count, by=count['Genus'], sum)