rename - Renaming Multiple variables sequentially in R -
i need rename hundreds of variables in dataset , i'm looking efficient way of doing this. when raw data imported, sas generates generic variable names "varx", , in r it's "vx". company moving sas r, , old sas code looked rename var23-var150=nrx1-nrx128;
rename "var23" "nrx1", "var24" "nrx2", , on. efficient shorthand in sas. know can use names(data)[x:y] = c("nrx1","nrx"2,etc)
read column x column y, renaming each variable along way. means i'd have write out nrx variables , feels waste of time.
theres set of variables after nrx, sas code looked rename var151-var278=trx1-trx128;
. in have rename 250 variables , need efficient way of writing code. i'm pretty new r, hints , shortcuts appreciated. in advance help!
i think initial approach works fine, rather typing new names out, create simple vector of new desired names:
names(data)[x:y] = paste0("nrx", 1:128)
you can modify goes in between "
, of course final number fit needs. 0
in paste0
signifies there no space in variable naming.
Comments
Post a Comment