To begin, make sure your R session has its working directory set to the same directory where your data is located. To view your current working directory, run the command getwd() in the R console. Use the R options File -> Change dir... in the RGui to set your working directory or use the setwd('insert/your/path/to/data.csv') command to set your working directory.
To double check that train.csv and test.csv are in your current working directory, the following command should return TRUE twice, as seen in the output below.
c('train.csv', 'test.csv') %in% list.files()
Now that we have an R session with our two data files in the working directory, read the comma separated data using the read.csv() function and view a few predictor summaries.
train = read.csv('train.csv')
head(train)
hist(train$Var4, main = "Histogram of Var4", xlab = "Var4")
summary(train$Var8)
Also read the test set into your R session via the read.csv() function.
test = read.csv('test.csv')
head(test)
plot(density(train$Var2), main = "Density of Var2")
dim(train)
dim(test)
The training and testing sets have a different number of columns. This is, of course, because the test set does not contain the response variable. The following command will tell us which column is contained in the training set and not in the testing set.
setdiff(names(train), names(test))
When making a submission, the predictions need to be exported in a certain fashion. The example below will generate random uniform numbers and use them as our predictions.
numberOfObservationsInTestSet = nrow(test)
vectorOfPredictions = runif(numberOfObservationsInTestSet, 0, 1)
summary(vectorOfPredictions)
outputDataSet = data.frame("RowID" = test$RowID,
"ProbabilityOfResponse" = vectorOfPredictions)
Inspect data set before export
head(outputDataSet)
The following command will output a comma separated file to the current working directory. Find your current working directory again by executing the getwd() command.
write.csv(outputDataSet, "submissionExample.csv", row.names = FALSE)