Search code examples
rheaderrownames

How do I name rows


I have a data set hdata(as picture1 shows):

enter image description here

row names were automatically given by R How do I name rows by y1 to y6 instead of v1 to v6 given by R?


Solution

  • We can change the column names with paste

    colnames(hdata) <- paste0('y', seq_along(hdata))
    

    Or use sub

    colnames(hdata) <- sub('v', 'y', colnames(hdata))