Simple data frame rowname trim question

The solution would be almost the same

df <- data.frame(x = 1:3, 
                 row.names = c("_ABC", "_DEF", "_GHI")
                 )
df
#>      x
#> _ABC 1
#> _DEF 2
#> _GHI 3

rownames(df) <- gsub(pattern = "_", replacement = "", x = rownames(df))
df
#>     x
#> ABC 1
#> DEF 2
#> GHI 3

Created on 2019-11-13 by the reprex package (v0.3.0.9000)
Note: Please make your questions providing a proper REPRoducible EXample (reprex) like the one above.

1 Like