I am working with the R programming language. I am trying to remove columns from my data frame which have the same names. For data frames within the global environment, I was able to do this successfully :
my_data = data.frame(var1 = c(1,2,3), var2 = c(1,2,9), var1 = c(5,6,3), check.names = FALSE)
head(my_data)
var1 var2 var1
1 1 1 5
2 2 2 6
3 3 9 3
library(dplyr)
no_dup <- my_data %>% subset(., select = which(!duplicated(names(.))))
var1 var2
1 1 1
2 2 2
3 3 9
My Question: I would like to run this code over RODBC/sqlQuery() . For instance, does anyone know if it is possible to run the following code?
library(RODBC)
library(sqldf)
con = odbcConnect("some name", uid = "some id", pwd = "abc")
#not sure if this is correct?
sample_query = sqlQuery(con, "my_data %>% subset(., select = which(!duplicated(names(.))))
")
Can someone please tell me if this is correct?
Thanks!