Changing the name of elements in a column I have a very big matrix like

&gt; head(mat[1:4,1:4])
                     Tumor_Sample_Barcode Chromosome Start_Position End_Position
1: LP6005334-DNA_H01_vs_LP6005333-DNA_H01       chr1        1026918      1026918
2: LP6005334-DNA_H01_vs_LP6005333-DNA_H01       chr1       15772155     15772155
3: LP6005334-DNA_H01_vs_LP6005333-DNA_H01       chr1       16054813     16054813
4: LP6005334-DNA_H01_vs_LP6005333-DNA_H01       chr1       24120222     24120222

&gt; dim(mat)
[1] 450754     53
&gt;


In Tumor_Sample_Barcode column I have the name of samples so that

&gt; unique(mat$Tumor_Sample_Barcode)
 [1] "LP6005334-DNA_H01_vs_LP6005333-DNA_H01"     "LP6005500-DNA_D03_vs_LP6005499-DNA_D03"    
 [3] "LP6005935-DNA_G02_vs_LP6005979-DNA_C01"     "LP6007600_vs_LP6007599"                    
 [5] "LP6008202-DNA_B03_vs_LP6008201-DNA_B03"     "LP6008269-DNA_F06_vs_LP6008268-DNA_G06"    
 [7] "LP6008334-DNA_A03_vs_LP6008335-DNA_E02"     "LP6008334-DNA_A04_vs_LP6008335-DNA_E03"    
 [9] "LP6008334-DNA_B02_vs_LP6008335-DNA_F01"     "LP6008334-DNA_C02_vs_LP6008335-DNA_G01"    
[11] "LP6008334-DNA_D02_vs_LP6008335-DNA_H01"     "LP6008336-DNA_F02_vs_LP6008333-DNA_F02"    
[13] "LP6008336-DNA_G01_vs_LP6008333-DNA_G01"     "LP6008336-DNA_H01_vs_LP6008333-DNA_H01"    
[15] "LP6008336-DNA_H02_vs_LP6008333-DNA_H02"     "LP6008337-DNA_A07_vs_LP6008338-DNA_E06"    
[17] "LP6008337-DNA_H06_vs_LP6008338-DNA_D06"     "LP6008460-DNA_A04_vs_LP6008340-DNA_D05__pv"
[19] "LP6008460-DNA_D01_vs_LP6008340-DNA_E02__pv" "LP6008460-DNA_F02_vs_LP6008340-DNA_E05"    
[21] "LP6008460-DNA_G03_vs_LP6008340-DNA_C05__pv"
&gt;


I want to change the name of these samples to A1... A21 but I don't know how

Can you help?

Thank you
If your data is in a dataframe you can make use of plyr. Using mapvalues() from this library, you can rename provide a list of keys and a list of values. Instead of explicitly listing the keys, we can just use unique(mat$Tumor_Sample_Barcode) [credit to @dc37]. I use the paste0 function here and the colon operator to generate the vector of A1,A2,...,A21. 

Assign the vector produced by mapvalues() to the column and you're off!

install.packages("plyr")
mat$Tumor_Sample_Barcode &lt;-
plyr::mapvalues(x=mat$Tumor_Sample_Barcode,
                from=unique(mat$Tumor_Sample_Barcode),
                to=paste0("A", 1:21))


I'd recommend keeping this column and adding a new column with your simplified sample names, but this is not what you requested.