I faced a problem while trying to re-arrange by data frame into long format. my table looks like this:
x <- data.frame("Accession"=c("AGI1","AGI2","AGI3","AGI4","AGI5","AGI6"),"wt_rep_1"=c(1,2,3,4,4,5), "wt_rep_2" = c(1,2,3,4,8,9), "mutant1_rep_1"=c(1,1,0,0,5,3), "mutant2_rep_1" = c(1,7,0,0,1,5), "mutant2_rep_2" = c(1,1,4,0,1,8) )
> x
Accession wt_rep_1 wt_rep_2 mutant1_rep_1 mutant2_rep_1 mutant2_rep_2
1 AGI1 1 1 1 1 1
2 AGI2 2 2 1 7 1
3 AGI3 3 3 0 0 4
4 AGI4 4 4 0 0 0
5 AGI5 4 8 5 1 1
6 AGI6 5 9 3 5 8
I need to create a column that I would name "genotype", and it would containt the first part of the name of the column before "_"
How to use
strsplit(names(x), "_")
for that?
and preferably loop...
please, anyone, help.