I have two databases below, the difference is in df2
I don't have the Value
column. For the first database I specified colnames(df1)[-c(1, 2)]
and for the second colnames(df2)[-1]
. Is there a way to make this generic, that works for both database df1
and database df2
, since it will always be the last two columns?
df1<- structure(
list(Category = c("ABC","FDE","ABC","FDE"),
Value = c(4,1,1,2),
x = c(5,4,3,2), y = c(5,4,0,2)),
class = "data.frame", row.names = c(NA, -4L))
colnames(df1)[-c(1, 2)]<-c("Test1","Test2")
df2<- structure(
list(Category = c("ABC","FDE","ABC","FDE"),
x = c(5,4,3,2), y = c(5,4,0,2)),
class = "data.frame", row.names = c(NA, -4L))
colnames(df2)[-1]<-c("Test1","Test2")