Consider a data set with a number of columns.
> data <- import.csv("data.csv")
> head(data[1])
> Output:
Sex
1 M
2 M
3 F
4 M
5 I
6 I
(Isolating the first column of my data set.) I want to change the F to M in all cases.
So I try the following:
> for (i in 1:6) {
if (data[i, 1] == F) {
data[i, 1] = M)
}
}
This leaves the data unchanged. So I tried to import the data like so:
> data <- import.csv("data.csv", stringsAsFactors = FALSE)
The loop method works now, but this is not OK because with the F, M, and I as strings I cannot perform the logistic regression that I need to.
Any suggestions on changing F to M but not introducing strings?