string - Remove part of variable name for all variables in R -
i have dataset in of variable names begin string prior "." batch remove whole dataset.for example:
frame <- data.frame("sec.xx" = rnorm(10), "sec2.zz" = rnorm(10), "sec3.yy" = rnorm(10)) names(frame)
i remove in of names prior "." such resulting variable names "xx", "zz", "yy". , thoughts.
you use sub
function.
> names(frame) <- sub(".*\\.", "", names(frame)) > names(frame) [1] "xx" "zz" "yy"
Comments
Post a Comment