Replace numbers with Boolean in r

1.6k views Asked by At

I want to use weka to predict future instances. I have a csv file and a small portion of it is as following:

enter image description here

I used r to read the file but I am not sure how to substitute the zeros with "No error" and anything besides zero to "Error". I would have left like this but unfortunately weka is not able to predict instances with numbers as the status.

Edit 2: I tried your solution and even though it changed the numbbers to error/no error, it erased the other columns. Did I do something wrong? I also wrote it to a file so it would be easier to see.

Output File

Edit 3:

dput(data)
structure(list(BoxType = structure(c(3L, 3L, 6L, 6L, 3L, 8L, 
3L, 3L, 6L, 4L, 4L, 3L, 3L, 4L, 6L, 6L, 3L, 6L, 2L, 4L, 3L, 3L, 
8L, 3L, 6L, 8L, 2L, 3L, 8L, 8L, 3L, 8L, 2L, 2L, 8L, 8L, 2L, 3L, 
8L, 3L, 4L, 3L, 3L, 3L, 2L, 2L, 6L, 4L, 3L, 4L, 4L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 3L, 4L, 2L, 6L, 6L, 4L, 4L, 4L, 6L, 3L, 4L, 6L, 3L, 
3L, 2L, 2L, 6L, 3L, 3L, 3L, 2L, 6L, 8L, 3L, 8L, 3L, 4L, 3L, 8L, 
6L, 2L, 6L, 6L, 3L, 3L, 4L, 3L, 4L, 4L, 2L, 4L, 2L, 3L, 2L, 6L, 
3L, 3L, 4L, 3L, 3L, 6L, 3L, 6L, 3L, 3L, 4L, 6L, 4L, 4L, 3L, 4L, 
4L, 2L, 6L, 2L, 6L, 6L, 3L, 3L, 4L, 3L, 4L, 6L, 3L, 4L, 6L, 6L, 
4L, 4L, 3L, 6L, 4L, 4L, 3L, 4L, 6L, 3L, 6L, 2L, 3L, 2L,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L, 3L, 2L, 3L, 
3L, 3L, 3L, 2L, 4L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 
2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 2L, 3L, 3L, 2L, 3L, 
2L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 
3L, 3L, 2L, 3L, 3L, 3L), .Label = c("", "CISCO", "MOTOROLA", 
"PACE"), class = "factor"), Receiver_TotalVideoDecoderErrors = c(3L, 
204L, 0L, 0L, 3393L, 909L, 1556L, 48L, 0L, 0L, 0L, 182L, 19L, 
0L, 0L, 0L, 77L, 0L, 0L, 0L, 6L, 1002L, 10L, 0L, 0L, 6938L, 0L, 
299L, 49L, 245L, 0L, 41L, 0L, 0L, 717L, 31L, 0L, 75L, 37L, 71L, 
0L, 40L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 
1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 22L, 0L, 0L, 1384L, 95L, 0L, 0L, 
0L, 437L, 119L, 910L, 0L, 0L, 8679L, 20L, 68L, 7L, 0L, 0L, 16L, 
0L, 0L, 0L, 0L, 74L, 1L, 0L, 82L, 0L, 0L, 0L, 0L, 0L, 21L, 0L, 
0L, 279L, 40L, 0L, 1483L, 3L, 0L, 132L, 0L, 0L, 171L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 90L, 0L, 0L, 0L, 0L, 
0L, 111L, 0L, 0L, 0L, 0L, 0L, 18L, 0L, 0L, 0L, 217L, 0L, 0L, 
1687L, 0L, 0L, 25L, 0L, 0L, 0L, 0L, 0L, 60L, 0L, 0L, 7L, 0L, 
0L, 0L, 0L, 1L, 20L, 0L, 0L, 0L, 0L, 0L, 230L, 0L, 169L, 0L, 
0L, 0L, 889L, 0L, 3L, 0L, 48L, 2951L, 10L, 531L, 0L, 0L, 0L, 
0L, 0L, 232L, 0L, 0L, 125L, 0L, 39L, 0L, 0L, 262L, 0L, 0L, 0L, 
0L, 1270L, 6L, 0L, 0L, 88L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 297L, 
124L, 419L, 0L, 483L, 280L, 0L, 0L, 127L, 93L, 368L, 0L, 209571L, 
0L, 0L, 21L, 62L, 11L, 0L, 501L, 0L, 169L, 34L, 32L, 25L, 188L, 
0L, 1596L, 0L, 41L, 183L, 0L, 805L, 3L, 0L, 0L, 0L, 0L, 297L, 
90L, 0L, 0L, 0L, 0L, 691L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, 23L, 
52L, 0L, 0L, 0L, 0L, 58L, 18L, 93L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 9L, 0L, 0L, 11381L, 0L, 34L, 0L, 0L, 26L, 0L, 0L, 0L, 318L, 
0L, 0L, 36L, 0L, 6534L, 22L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 
30L, 0L, 0L, 0L, 51L, 0L, 7L, 0L, 84L, 0L, 9L, 0L, 0L, 48L, 65L, 
23L, 0L, 60312L, 0L, 0L, 28L, 0L, 32L, 0L, 0L, 283L, 406L, 44L, 
0L, 0L, 0L, 2L, 824L, 0L, 0L, 2487L, 95L, 0L, 0L, 0L, 0L, 0L, 
56L, 0L, 1L, 4640L, 12L, 3626L, 0L, 0L, 0L, 420L,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 4L, 1L, 0L, 0L, 5L, 0L, 548L, 123L, 387L, 
723L, 0L, 522L, 384L, 0L, 0L, 0L, 0L, 472L, 1L, 0L, 0L, 0L, 24L, 
0L, 91L, 0L, 0L, 11L, 47L, 0L, 11L, 0L, 0L, 27L, 17L, 156L, 0L, 
29L, 5L, 0L, 0L, 0L, 15L, 79L, 0L, 0L, 0L, 137L, 0L, 75L, 0L, 
0L, 0L, 0L, 0L, 0L, 670L, 0L, 0L, 0L, 17L, 23L, 1L, 0L, 160L, 
0L, 0L, 235L, 0L, 272L, 16L, 0L, 1803L, 0L, 4780L, 26L, 0L, 90L, 
17L, 0L, 1518L, 151L, 1L, 768L, 151L, 42L, 0L, 9161L, 57L, 0L, 
0L, 73L, 0L, 0L, 0L, 0L, 3086L, 0L, 0L, 0L, 1896L, 0L, 240L, 
165L, 0L, 0L, 722L, 282L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 4L, 0L, 
0L, 0L, 0L, 212L, 0L, 0L, 0L, 0L, 285L, 0L, 0L, 9L, 1349L, 1417L, 
30792L, 2163L, 0L, 0L, 0L, 0L, 969L, 0L, 0L, 0L, 8L, 0L, 100L, 
109L, 48L, 0L, 100L, 109L, 48L, 0L, 0L, 61L, 0L, 0L, 0L, 86L, 
967L, 2679L, 86L, 967L, 2679L, 0L, 0L, 0L, 32L, 0L, 0L, 32L, 
0L, 4L, 0L, 0L, 54L, 341L, 0L, 54L, 341L, 0L, 0L, 0L, 0L, 401L, 
83L, 83L, 6L, 0L, 0L, 46L, 442L, 0L, 46L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 245L, 0L, 245L, 599L, 78L, 0L, 58L, 54L, 
0L, 54L, 0L, 0L, 16L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 305L, 0L, 
305L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 27L, 0L, 0L, 0L, 0L, 536L, 0L, 0L, 0L, 10L, 66L, 
20L, 66L, 899L, 4L, 0L, 0L, 233L, 0L, 0L, 0L, 0L, 233L, 3L, 0L, 
0L, 8L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 428L, 0L, 0L, 0L, 428L, 
0L, 172L, 0L, 0L, 0L, 12L, 13L, 13L, 0L, 35L, 0L, 0L, 0L, 0L, 
0L, 0L, 49L, 0L, 0L, 0L, 0L, 639L, 0L, 78L, 0L, 4386L, 78L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2076L, 6L, 0L, 0L
)), .Names = c("BoxType", "BoxVendor", "Receiver_TotalVideoDecoderErrors"
), class = "data.frame", row.names = c(NA, -999L))
2

There are 2 answers

4
shadowtalker On BEST ANSWER

The ifelse way

Assuming your CSV has been loaded into a data frame called boxdata with the same column names as in the CSV:

ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error')

Explanation

The best way to demonstrate ifelse is by example:

x <- 1:5

x_lessthan_4 <- x < 4
x_lessthan_4
# [1]  TRUE  TRUE  TRUE FALSE FALSE

if_lessthan_4 <- -x
if_lessthan_4
# [1] -1 -2 -3 -4 -5 

if_notlessthan_4 <- x + 100
if_notlessthan_4
# [1] 101 102 103 104 105

ifelse(test = if_notlessthan_4,
       yes = if_lessthan_4,
       no = if_notlessthan_4)
# [1]  -1  -2  -3 104 105

Hopefully it's clear what this function does. Obviously you don't need to always name the arguments as long as they're in the right order; I'm just doing it here so you can see exactly what's going on.

However, you'll notice that the expression

ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error')

does not conform to this standard. It works because two things happen "under the hood":

  1. test is "coerced" to logical, so if I pass in something like test = c(1, 3, 0) the value of test will be replaced with as.logical(test), so test = c(1, 3, 0) becomes test = c(TRUE, TRUE, FALSE).
  2. yes and no are "recycled" if they are shorter than test, and truncated if they are longer.

Recycling is again best demonstrated by example:

test <- c(TRUE, FALSE, TRUE, TRUE, FALSE)
yes <- c(1, 2, 3)
no <- c(99, 100, 101, 102, 103, 104)
c(length(test), length(yes), length(no))
# [1] 5 3 6
ifelse(test, yes, no)
# [1]   1 100   3   1 103

These things are documented, but they're easy to miss if you're not used to reading the R help files.

And finally, the help file also says this, which is worth pointing out:

Missing values in test give missing values in the result.

This means that ifelse(c(NA, 1, 0, 1), 99, 100) returns c(NA, 99, 100, 99).

So

ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error')

is equivalent to

test <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors)
yes <- rep('Error', length(test))
no <- rep('No error', length(test))
ifelse(test, yes, no)

The slick way

Or let argument recycling to do the work for you. Shorter and more efficient, but maybe less readable to someone who isn't familiar with R:

c('No error', 'Error')[as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1]

or

c('Error', 'No error')[!as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1]

Explanation

First, the statement

as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1

is equivalent to:

i <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors)
i <- as.numeric(i)  # FALSE -> 0, TRUE -> 1
i <- i + rep(1, length(i))

Finally, recycling is applied to subsetting as well:

c('No error', 'Error')[c(1, 2, 1, 1, 2)]
# [1] "No error" "Error"    "No error" "No error" "Error"

So the entire thing is equivalent to:

i <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors)
i <- as.numeric(i)
i <- i + rep(1, length(i))
c('No error', 'Error')[i]

The long way (suggested here)

This way doesn't need much explanation. It's a lot more typing but it's easy to read and it's flexible:

x <- boxdata$Receiver_TotalVideoDecoderErrors
x[x > 0] <- 'Error'
x[x == 0] <- 'No error'
2
Alex Witsil On

Try using the which command and some logical operators to quickly determine the index locations for the values that are equal to 0 and those that are greater than 0. From there you can replace the original numeric values with a string. Try something like this:

data$Receiver_TotalVideoDecoderErrors[which(data$Receiver_TotalVideoDecoderErrors == 0)] = "no error"
data$Receiver_TotalVideoDecoderErrors[which(data$Receiver_TotalVideoDecoderErrors > 0)] = "error"

Hope that helps.