Skip to content

Instantly share code, notes, and snippets.

@cseidman
Last active January 24, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cseidman/7dae96bb097b2ef5256356f545ecd73c to your computer and use it in GitHub Desktop.
Save cseidman/7dae96bb097b2ef5256356f545ecd73c to your computer and use it in GitHub Desktop.
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