I have a dataframe that looks like this.
> head(zeisel)
gene_name ClusterName p
1 GNAI3 ABC 0.29914
2 GNAI3 ACBG 0.33417
3 GNAI3 ACMB 0.21984
4 GNAI3 ACNT1 0.14727
5 GNAI3 ACNT2 0.22205
6 GNAI3 ACOB 0.16913
I would like to convert it into this:
Is there a way to do this? I tried setting the names first, but this would mean iteratively rbinding every row.
For example:
#get name of new df
cells <- as.data.frame(table(df$ClusterName))
#now create an empty dataframe.
unmelted_df <- setNames(data.frame(matrix(ncol = length(cells$Var1), nrow = 0)), as.character(cells$Var1))
Is there a way to do this in one step for a massive dataframe?