jeudi 14 juin 2018

if statement is true assing new character string in a new column

I have a matrix M with a row names in a format like below, which represent 4 unique individual, S003,S004, SuperSMART_27,SuperSMART_42;

S003_T1_p555
S003_T2_p456
S004_T3_p785
S004_T4_p426
SuperSMART_27_T1_p112
SuperSMART_27_T2_p414
SuperSMART_42_T3_p155
SuperSMART_42_T5_p775

I need to make a data frame df with rows equal to my matrix row names and a new column NC in my df, where I assign a unique name to each similar individual, so both S003_T1_p555 and S003_T2_p456 become "group1", S004_T3_p785 and S004_T4_p426 "group2", and so on.

df <- data.frame(sample= row.names(M))
df$NC <- ?

Thanks !

Aucun commentaire:

Enregistrer un commentaire