Starting on R 2.13, I want to have data.frame from several columns, the first of which has a numeric type, the other type of character. When I create my object, the values of the first column are converted in such a way that I do not expect and do not understand. See code below.
tmp <- cbind (1:10, rep ("aa", 10))
Tmp
[,1] [,2]
[1,] "1" "aa"
[2,] "2" "aa"
[3,] "3" "aa"
[4,] "4" "aa"
[5,] "5" "aa"
[6,] "6" "aa"
[7,] "7" "aa"
[8,] "8" "aa"
[9,] "9" "aa"
[10,] "10" "aa"
tmp <- data.frame (tmp)
Tmp
X1 X2
1 1 aa
2 2 aa
3 3 aa
4 4 aa
5 5 aa
6 6 aa
7 7 aa
8 8 aa
9 9 aa
10 10 aa
tmp [, 1] <- as.numeric (tmp [, 1])
Tmp
X1 X2
1 1 aa
2 3 aa
3 4 aa
4 5 aa
5 6 aa
6 7 aa
7 8 aa
8 9 aa
9 10 aa
10 2 aa
For some reason, the values of the first column are changing. I have to do something obviously wrong here, can someone tell me a workaround?
source
share