Skip to content

Instantly share code, notes, and snippets.

@cseidman

cseidman/getFullDataset.R Secret

Last active Jan 24, 2018
Embed
What would you like to do?
Get full dataset
# Define the SQL Connection string and the query
sqlServerConnString <- "SERVER=winrserver;DATABASE=AdventureWorksDW2017;UID=ruser;PWD=rpass"
qry <- "select
[Age]
,[MaritalStatus]
,[Gender]
,[YearlyIncome]
,[TotalChildren]
,[NumberChildrenAtHome]
,[Education]
,[Occupation]
,[IsHomeOwner]
,[NumberCarsOwned]
,[YearsSinceFirstPurchase]
,[CommuteDistance]
,[CountryRegionCode]
,[StateProvinceCode]
,[IsCardUser]
from dbo.vwDimCustomer"
# Get the results into a dataset
sqlData <- RxSqlServerData(sqlQuery = qry, connectionString = sqlServerConnString,stringsAsFactors = TRUE)
ds <- rxDataStep(sqlData,reportProgress=0)
# Factorize some continuous values in order to avoid nonsensical value splits such as <2.5 children and 1.5 cars
ds$TotalChildren <- as.factor(ds$TotalChildren)
ds$NumberChildrenAtHome <- as.factor(ds$NumberChildrenAtHome)
ds$NumberCarsOwned <- as.factor(ds$NumberCarsOwned)
ds$YearsSinceFirstPurchase <- as.factor(ds$YearsSinceFirstPurchase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.