Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Renaming Variables Dynamically

$
0
0

I have a file named 'schema'. Based on the file, I need to rename other data frames. For example, 'Var1' of TableA needs to be renamed to 'Col1'. Similarly, VarA of TableA needs to be renamed to ColA. In short, all variables listed in 'FROM' colume of schema needs to be renamed to column 'To'.

Schema <- read.table(header = TRUE, text = 
                  'Tables   From    To
                A   Var1    Col1
                A   Var2    Col2
                A   Var3    Col3
                B   VarA    ColA
                B   VarB    ColB
                B   VarC    ColC
                ')


A <- data.frame(Var1 = 1:3,
                  Var2 = 2:4,
                  Var3 = 3:5)

B <- data.frame(VarA = 1:3,
                VarB = 2:4,
                VarC = 3:5)

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>