Setting the labels for columns of a data table from another table in R

r
data_wrangling

#1

Hi,

I have a data table ‘x_train’ with 7352 rows and 561 columns and in another data table ‘features’ I have 561 rows and 2 columns. I want to set the column labels for x_train to be equal to the names in the second column of features.

How can I do this?


#2

Hi @Aditya_Sharma,

Suppose the label for your second column of features is ‘label2’. You can then use

colnames(x_train)=features$label2

This would set the names in the second column of features as the labels for columns of x_train.

Hope this helps.