Character to NA

How do I convert character values into NA, say in this vector:

[1] "0" "0"
[3] "0" "0"
[5] "0" "1"
[7] "1" "0"
[9] "0" "1"
[11] "0" "0"
[13] "არ ვცხოვრობთ ერთად" "0"
[15] "0" "0"
[17] "0" "0"
[19] "1" "0"
[21] "1" "0"
[23] "0" "0"
[25] "0" "0"
[27] "0" "0"
[29] "1" "0"
[31] "0" "1"
[33] "0" "o"
[35] "0" "0"
[37] "0" "0"
[39] "0" "0"
[41] "1" "0"
[43] "0" "0"
[45] "1" "0"
[47] "0" "0"
[49] "0" "არ მყავს"
[51] "0" "არცერთი"
[53] "0" "0"
[55] "0" "0"
[57] "0" "0"
[59] "0" "0"
[61] "0" "0"
[63] "არცერთი" "2"
[65] "0" "1"
[67] "1" "0"
[69] "1" "0"
[71] "-" "0"
[73] "0" "-"
[75] "0" "0"
[77] "1" "25 wels zevut aravinaa"
[79] "ბაბუ" "0"
[81] "არ გვყავს" "1"
[83] "0" "25 cels zemot"
[85] "0" "0"
[87] "1" "2"
[89] "2" "არ არის ასეთი"
[91] "1" "0"
[93] "0" "0"
[95] "0" "0"
[97] "-" "0"
[99] "0" "0"
[101] "0" "0"

The as.numeric() function will do that.

Vec <- c("0","0","0","0","0","1","1","0","0","1","0","0","არ ვცხოვრობთ ერთად", "0")
Vec <- as.numeric(Vec)
Warning message:
NAs introduced by coercion 
Vec
 [1]  0  0  0  0  0  1  1  0  0  1  0  0 NA  0
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you for answering my questions. This solution seems simple.