2

Similar to this SO question, I have a data.frame of floats which I would like to convert to a set of Boolean values.

Specifically, I would like to go through a matrix (data.frame) where each cell is replaced with "if this cell is the maximum of all cells in this row"

For example, given the following data.frame,

row.names   net.result.1  net.result.2  net.result.3 net.result.4
1            0.000013,     0.0156616,    0.000005,    0.999959
2            0.000046,     0.0145417,    0.000005,    0.999945
3            0.938103,     0.0043157,    0.000007,    0.002126
4            0.000000,     0.0000000,    0.999811,    0.000000

Produce the following binary values:

FALSE, FALSE, FALSE, TRUE
FALSE, FALSE, FALSE, TRUE
TRUE,  FALSE, FALSE, FALSE
FALSE, FALSE, TRUE,  FALSE

How would I go about doing this?

1 Answer 1

2

For example:

dat == apply(dat, 1, max) 
        V1    V2    V3    V4
[1,] FALSE FALSE FALSE  TRUE
[2,] FALSE FALSE FALSE  TRUE
[3,]  TRUE FALSE FALSE FALSE
[4,] FALSE FALSE  TRUE FALSE
Sign up to request clarification or add additional context in comments.

4 Comments

This seems to return a vector of only the max values. The 'max' operator seems to be returning the max value of each row.
I've updated the question with a more detailed representation of my data
@Peaches491 Sorry I don't get your point. apply(dat, 1, max) returns the max of each row, that I compare to your matrixx...
OHHH. I missed the '==', and was only using a single equals sign. Works perfectly now! Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.