Suppose I have a data frame as follows:
dat <- data.frame(
ee=1:4,
bb = 4:7,
cc =4:7,
dd = 2:5
)
rownames(dat) <- colnames(dat)
dat
ee bb cc dd
ee 1 4 4 2
bb 2 5 5 3
cc 3 6 6 4
dd 4 7 7 5
How can I replace the cell value to 1 where column and row names are the same? also suppose that the position may not in the diagonal the position needing replacement can occur in an arbitrary position.