Hi,
I'm new to R and I have a question about recoding variables from taken from our SQL database.
My starting point is preparing a file:
library(RODBC)
abc <- odbcConnect("sqldatabase")
my.data <- sqlQuery(abc, "SELECT * FROM sqldatatable")
my.local.data <- collect(my.data)
Belgium.data <- my.data[my.data$CountryID == 15, ]
Belgium.CurrentHY.data <- subset(Belgium.data, InterviewDate > "2018-04-01" & InterviewDate < "2018-09-30")
I can display it without any problems:
str(Belgium.CurrentHY.data)
$ CountryID : int 15 15 15 15 15 15 15 15 15 15 ... $ InterviewDate : POSIXct, format: "2018-04-25 08:12:00" "2018-04-26 13:05:00" "2018-04-04 17:28:00" "2018-04-10 12:12:00" ...
$ A2 : int 9 10 10 8 10 9 10 10 9 10 ...
$ B1 : int 10 10 8 7 10 8 9 10 8 10 ...
$ C1 : int 10 10 9 8 10 9 10 9 9 9 ...
so Belgium.CurrentHY.data exists
Now, I would like to recode variable A2 (values from 1 to 10) into A2TB (values 9-10 as 1 and values 1-8 as 2).
How can I do that?