Skip to content
Prev 390998 / 398513 Next

how to rename variables by lopping off first 3 characters

If you care to entertain this, one of many simple base R ways to do this is:

dat <- data.frame(
+    i..One = 1:3,
+    i..Two = letters[1:3],
+    ixx = 5:7)
i..One i..Two ixx
1      1      a   5
2      2      b   6
3      3      c   7
+              substring(nm,4),
+              nm)
One Two ixx
1   1   a   5
2   2   b   6
3   3   c   7

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Mar 14, 2022 at 9:27 AM Christopher W Ryan via R-help
<r-help at r-project.org> wrote: