How to remove double inverted commas in R matrix?


To remove double inverted commas in R matrix, we can follow the below steps −

  • First of all, create a matrix.

  • Then, use print function along with quote argument.

Example

Create the matrix

Let’s create a matrix as shown below −

M<-matrix(sample(c("india","china","uk","russia","qatar"),25,replace=TRUE))
M

Output

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

       [,1]
[1,]  "russia"
[2,]  "russia"
[3,]  "russia"
[4,]  "qatar"
[5,]  "india"
[6,]  "qatar"
[7,]  "qatar"
[8,]  "india"
[9,]  "china"
[10,] "india"
[11,] "india"
[12,] "uk"
[13,] "russia"
[14,] "india"
[15,] "qatar"
[16,] "india"
[17,] "china"
[18,] "qatar"
[19,] "qatar"
[20,] "china"
[21,] "india"
[22,] "russia"
[23,] "china"
[24,] "qatar"
[25,] "qatar"

Remove double inverted commas

Using print function along with quote argument to remove double inverted commas −

M<-matrix(sample(c("india","china","uk","russia","qatar"),25,replace=TRUE))
print(M,quote=FALSE)

Output

       [,1]
[1,]  russia
[2,]  russia
[3,]  russia
[4,]  qatar
[5,]  india
[6,]  qatar
[7,]  qatar
[8,]  india
[9,]  china
[10,] india
[11,] india
[12,] uk
[13,] russia
[14,] india
[15,] qatar
[16,] india
[17,] china
[18,] qatar
[19,] qatar
[20,] china
[21,] india
[22,] russia
[23,] china
[24,] qatar
[25,] Qatar

Updated on: 15-Nov-2021

127 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements