I have a matrix that looks like the following:
> m <- cbind( c(1, 0), c(1, 1) )
> rownames(m) <- c('ON', 'OFF')
> colnames(m) <- c('ON', 'OFF')
> m
    ON OFF
ON   1   1
OFF  0   1
How can I provide a header name for the rows and columns? E.g.
                  thermostat
                  ON OFF
motion_sensor ON   1   1
              OFF  0   1
I had a look at ?dimnames but couldn't see/understand how to do this.
Try with names.  dimnames is a list.  In your example, there were no names for the list elements, which can be assigned using names
 names(dimnames(m)) <- c('motion_sensor', 'thermostat')
 m
 #            thermostat
 #motion_sensor ON OFF
 #         ON   1   1
 #         OFF  0   1
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With