Hope that helps mode(B) <- "logical" or "mode<-"(B, "logical"). We can also use storage.mode function.

code :

```
## an integer matrix
A <- matrix(1:4, nrow = 2, dimnames = list(letters[1:2], LETTERS[1:2]))
# A B
#a 1 3
#b 2 4
```

```
"mode<-"(A, "numeric")
# A B
#a 1 3
#b 2 4
"mode<-"(A, "logical")
# A B
#a TRUE TRUE
#b TRUE TRUE
"mode<-"(A, "chracter")
# A B
#a "1" "3"
#b "2" "4"
"mode<-"(A, "complex")
# A B
#a 1+0i 3+0i
#b 2+0i 4+0i
str("mode<-"(A, "list")) ## matrix list
#List of 4
# $ : int 1
# $ : int 2
# $ : int 3
# $ : int 4
# - attr(*, "dim")= int [1:2] 2 2
# - attr(*, "dimnames")=List of 2
# ..$ : chr [1:2] "a" "b"
# ..$ : chr [1:2] "A" "B"
```

```
f <- factor(c("a", "b"))
## this "surprisingly" doesn't work
mode(f) <- "character"
#Error in `mode<-`(`*tmp*`, value = "character") :
# invalid to change the storage mode of a factor
## this also doesn't work
mode(f) <- "numeric"
#Error in `mode<-`(`*tmp*`, value = "numeric") :
# invalid to change the storage mode of a factor
## this does not give any error but also does not change anything
## because a factor variable is internally coded as integer with "factor" class
mode(f) <- "integer"
f
#[1] a b
#Levels: a b
```