I have a vector like this
[1] "72.82947" NA NA NA NA NA "66.00949" NA
[9] NA "0.133434" NA NA "2.265083" NA NA NA
[17] " 0" NA NA NA NA NA NA NA
[25] "0.311346" NA NA " 0" NA NA NA NA
[33] NA NA NA NA NA "0.7024582" NA NA
[41] NA NA NA NA NA NA "3.543211" NA
[49] NA "5.779669" NA "4.617021" NA "1.682751" NA NA
[57] NA NA NA "0.214977" NA NA NA "1.573152"
Following many previous questions (How to remove all the NA from a Vector?, R script - removing NA values from a vector, R: removing NAs in numerical vectors ) and manuals I used
vector.test[!is.na(exo.1.4.mad)]
and
vector.test[na.omit(exo.1.4.mad)]
But none of them works. I always get back the same vector with NA. Then I tried to subset the vector manually, indicating the position where I have values and I tried to convert it in numeric values:
as.numeric(as.character(exo.1.4.mad.values))
But also this does not work, and NAs are introduced by coercion. At this point I think I'm missing something concerning the formatting/class of my original vector.
Any suggestion?
I add some more information for my object:
typeof(exo.1.4.mad) 1 "integer"
dput(exo.1.4.mad) structure(c(33L, 37L, 37L, 37L, 37L, 37L, 31L, 37L, 37L, 4L, 37L, 37L, 20L, 37L, 37L, 37L, 1L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 8L, 37L, 37L, 1L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 11L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 24L, 37L, 37L, 29L, 37L, 26L, 37L, 19L, 37L, 37L, 37L, 37L, 37L, 6L, 37L, 37L, 37L, 18L, 37L, 2L, 37L, 1L, 37L, 14L, 37L, 25L, 37L, 27L, 37L, 10L, 37L, 3L, 37L, 37L, 35L, 37L, 37L, 28L, 37L, 37L, 37L, 32L, 37L, 12L, 37L, 30L, 37L, 37L, 37L, 37L, 37L, 36L, 37L, 37L, 7L, 37L, 13L, 37L, 37L, 37L, 37L, 9L, 37L, 37L, 37L, 21L, 37L, 37L, 37L, 37L, 37L, 37L, 15L, 37L, 37L, 37L, 34L, 37L, 23L, 37L, 37L, 37L, 37L, 37L, 22L, 37L, 37L, 37L, 16L, 37L, 37L, 17L, 37L, 5L, 37L), .Label = c("\" 0\"", "\"0.044478\"", "\"0.1103672\"", "\"0.133434\"", "\"0.1893487\"", "\"0.214977\"", "\"0.2506812\"", "\"0.311346\"", "\"0.3219932\"", "\"0.409485\"", "\"0.7024582\"", "\"0.7029872\"", "\"0.7983231\"", "\"1.104537\"", "\"1.170474\"", "\"1.2355\"", "\"1.255681\"", "\"1.573152\"", "\"1.682751\"", "\"2.265083\"", "\"2.491765\"", "\"2.566038\"", "\"2.731105\"", "\"3.543211\"", "\"4.42271\"", "\"4.617021\"", "\"5.235322\"", "\"5.340412\"", "\"5.779669\"", "\"5.847934\"", "\"66.00949\"", "\"67.9525\"", "\"72.82947\"", "\"75.2123\"", "\"8.347973\"", "\"9.832462\"", "NA"), class = "factor")
this confuses me even more!
as.numeric
should help. – Manoj Gstr(vector.test)
? – David Arenburgna.omit
might not work here. but youris.na
command should have worked. You could try this as well...as.numeric(vect.test[complete.cases(vect.test)])
– Manoj G> str(exo.1.4.mad) Factor w/ 37 levels "\" 0\"","\"0.044478\"",..: 33 37 37 37 37 37 31 37 37 4 ...
– efrem[1] 33 37 37 37 37 37 31 37 37 4 37 37 20 37 37 37 1 37 37 37 37 37 37 37 8 37 37 1 37 37 37 37 37 [34] 37 37 37 37 11 37 37 37 37 37 37 37 37 24 37 37 29 37 26 37 19 37 37 37 37 37 6 37 37 37 18 37 2 [67] 37 1 37 14 37 25 37 27 37 10 37 3 37 37 35 37 37 28 37 37 37 32 37 12 37 30 37 37 37 37 37 36 37
– efrem