2
I have a database that contains 3 variables: var1, var2 and var 3. I tried to use some functions in R that would return me a logical value if any of the lines had the same values. One of them was the function all, as below:
apply(meusdados,1,all)
However, I noticed that she returns TRUE only for values other than 0 if there is repetition.
[1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
Aléḿ of this, this function does not work with vectors with characters, returning everything NA.
How to fix this so that if identical lines return the value Boolean TRUE?
My data with numerical variables are these:
structure(list(var1 = c(1, 0, 1, 0, 1, 0, 1, 0, 0, 1), var2 = c(0,
0, 0, 1, 1, 1, 0, 0, 1, 1), var3 = c(1, 0, 1, 1, 1, 1, 0, 0,
0, 0)), .Names = c("var1", "var2", "var3"), class = "data.frame", row.names = c(NA,
-10L))
With the strings, these are:
structure(list(var1 = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 1L, 2L), .Label = c("compras", "opfin"), class = "factor"),
var2 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L
), .Label = c("compras", "opfin"), class = "factor"), var3 = structure(c(2L,
1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("compras",
"opfin"), class = "factor")), .Names = c("var1", "var2",
"var3"), row.names = c(NA, -10L), class = "data.frame")