I am trying to debug a code in R
in order to understand it. The statements are as follows:
library(rpart)
X = read.csv("strange_binary.csv");
fit = rpart(c ~ X + X.1 + X.2 + X.3 + X.4 + X.5 + X.6 + X.7 + X.8 + X.9, method ="class",data=X,minbucket=1,cp=.04);
printcp(fit);
fit = prune(fit,cp=.04);
pred = predict(fit,X[,1:10],type="vector") # test the classifier on the training data
pred[pred == 2] = "bad"
pred[pred == 1] = "good"
The aim is to build a classifier and to test it on the training data. However, I do not understand the statements:
pred[pred == 2] = "bad"
pred[pred == 1] = "good"
pred==2
and pred==1
would be either TRUE
or FALSE
- how is it being used to index a vector? Sorry for my naive question, I am from a C++ background and taking baby steps in R.
Thanks for your help!