How to remove double inverted commas in R vector?

R ProgrammingServer Side ProgrammingProgramming

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

  • First of all, create a vector.

  • Then, use print function along with quote argument.

Example 1

Create the vector

Let’s create a vector as shown below −

x1<-sample(c("1","2","3","4","5","6","7","8","9","10"),250,replace=TRUE)
x1

Output

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

 [1]   "8" "10" "3"  "5"  "6"  "10" "7"  "9" "1" "10"  "1"  "2" "1"  "8"
[15]   "6" "8"  "3"  "10" "2"  "9"  "4"  "5" "10" "6"  "5"  "6" "8"  "5"
[29]   "6" "7"  "1"  "2"  "4"  "4"  "10" "8" "7"  "5"  "8"  "9" "4"  "2"
[43]   "3" "8"  "6"  "6"  "10" "9"  "9"  "3" "8"  "2"  "10" "1" "2"  "4"
[57]   "1" "1"  "2"  "6"  "6"  "7"  "6"  "8" "8"  "2"  "5"  "4" "8"  "5"
[71]   "6" "4"  "4"  "10" "2"  "8"  "10" "3" "6"  "7"  "9"  "4" "2"  "3"
[85]   "9" "5"  "6"  "9"  "5"  "6"  "3"  "4" "7"  "5"  "2"  "9" "10" "9"
[99]   "1" "5"  "8"  "9"  "9"  "2"  "10" "7" "5"  "8"  "9"  "9" "2"  "1"
[113]  "7" "9"  "4"  "8"  "1"  "10" "3"  "7" "8"  "9"  "8"  "9" "6"  "9"
[127]  "5" "1"  "8"  "10" "5"  "6"  "1"  "8" "6"  "2"  "10" "6" "4"  "10"
[141] "10" "8"  "2"  "4"  "9"  "3"  "4"  "8" "4"  "4"  "8"  "7" "5"  "9"
[155]  "9" "2"  "9"  "3"  "3"  "10" "2"  "1" "6"  "3"  "2"  "1" "1"  "6"
[169]  "6" "10" "7"  "8"  "2"  "3"  "6"  "5" "9"  "5"  "5"  "1" "4"  "8"
[183]  "5" "9"  "9"  "2"  "7"  "5"  "8"  "6" "8"  "1"  "4"  "4" "6"  "5"
[197]  "3" "9"  "3"  "3"  "5"  "9"  "1"  "5" "4"  "8"  "7"  "9" "9"  "4"
[211]  "7" "7"  "10" "7"  "7"  "7"  "7"  "6" "9"  "1"  "5"  "8" "4"  "1"
[225]  "5" "6"  "2"  "9"  "4"  "9"  "4"  "4" "6"  "10" "7"  "3" "1"  "1"
[239]  "4" "10" "8"  "8"  "2"  "10" "7" "6"  "4"  "1"  "5"  "3"

Remove double inverted commas

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

x1<-sample(c("1","2","3","4","5","6","7","8","9","10"),250,replace=TRUE)
print(x1,quote=FALSE)

Output

 [1]  8 10 3  5  6 10 7 9  1 10  1 2 1 8 6  8  3 10 2  9  4  5 10  6
[25]  5  6 8  5  6  7 1 2  4  4 10 8 7 5 8  9  4  2 3  8  6  6 10  9
[49]  9  3 8  2 10  1 2 4  1  1  2 6 6 7 6  8  8  2 5  4  8  5  6  4
[73]  4 10 2  8 10  3 6 7  9  4  2 3 9 5 6  9  5  6 3  4  7  5  2  9
[97] 10  9 1  5  8  9 9 2 10  7  5 8 9 9 2  1  7  9 4  8  1 10  3  7
[121] 8  9 8  9  6  9 5 1  8 10  5 6 1 8 6  2 10  6 4 10 10  8  2  4
[145] 9  3 4  8  4  4 8 7  5  9  9 2 9 3 3 10  2  1 6  3  2  1  1  6
[169] 6 10 7  8  2  3 6 5  9  5  5 1 4 8 5  9  9  2 7  5  8  6  8  1
[193] 4  4 6  5  3  9 3 3  5  9  1 5 4 8 7  9  9  4 7  7 10  7  7  7
[217] 7  6 9  1  5  8 4 1  5  6  2 9 4 9 4  4  6 10 7  3  1  1  4 10
[241] 8  8 2 10  7  6 4 1  5  3

Example 2

Create the vector

Let’s create a vector as shown below −

x2<-
sample(c("ID01","ID02","ID03","ID04","ID05","ID06","ID07","ID08"),200,replace=TRUE)
x2

Output

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

 [1]  "ID01" "ID05" "ID08" "ID03" "ID03" "ID07" "ID05" "ID07" "ID07" "ID04"
[11]  "ID08" "ID06" "ID04" "ID04" "ID02" "ID02" "ID01" "ID02" "ID04" "ID03"
[21]  "ID07" "ID04" "ID07" "ID04" "ID07" "ID06" "ID03" "ID03" "ID06" "ID05"
[31]  "ID06" "ID02" "ID02" "ID01" "ID01" "ID04" "ID02" "ID01" "ID03" "ID08"
[41]  "ID04" "ID08" "ID06" "ID05" "ID03" "ID07" "ID08" "ID02" "ID07" "ID05"
[51]  "ID02" "ID07" "ID04" "ID04" "ID03" "ID08" "ID06" "ID08" "ID04" "ID04"
[61]  "ID08" "ID08" "ID05" "ID02" "ID04" "ID07" "ID08" "ID05" "ID03" "ID04"
[71]  "ID03" "ID06" "ID06" "ID05" "ID03" "ID02" "ID02" "ID04" "ID03" "ID04"
[81]  "ID03" "ID08" "ID02" "ID05" "ID08" "ID08" "ID05" "ID05" "ID08" "ID08"
[91]  "ID08" "ID06" "ID02" "ID02" "ID02" "ID06" "ID06" "ID07" "ID02" "ID07"
[101] "ID06" "ID06" "ID03" "ID02" "ID07" "ID05" "ID06" "ID07" "ID01" "ID07"
[111] "ID06" "ID04" "ID06" "ID06" "ID01" "ID01" "ID08" "ID07" "ID04" "ID05"
[121] "ID03" "ID07" "ID04" "ID07" "ID02" "ID02" "ID02" "ID04" "ID06" "ID03"
[131] "ID08" "ID07" "ID02" "ID06" "ID02" "ID05" "ID07" "ID05" "ID04" "ID04"
[141] "ID06" "ID08" "ID04" "ID03" "ID06" "ID02" "ID06" "ID03" "ID05" "ID04"
[151] "ID03" "ID08" "ID01" "ID01" "ID08" "ID06" "ID08" "ID05" "ID01" "ID04"
[161] "ID03" "ID01" "ID06" "ID08" "ID03" "ID08" "ID07" "ID02" "ID01" "ID02"
[171] "ID04" "ID03" "ID06" "ID01" "ID03" "ID08" "ID01" "ID05" "ID07" "ID07"
[181] "ID02" "ID08" "ID06" "ID07" "ID07" "ID03" "ID04" "ID05" "ID03" "ID08"
[191] "ID07" "ID08" "ID05" "ID02" "ID03" "ID03" "ID04" "ID07" "ID07" "ID05"

Remove double inverted commas

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

x2<-
sample(c("ID01","ID02","ID03","ID04","ID05","ID06","ID07","ID08"),200,replace=TRUE)
print(x2,quote=FALSE)

Output

 [1]  ID01 ID05 ID08 ID03 ID03 ID07 ID05 ID07 ID07 ID04 ID08 ID06 ID04 ID04
[15]  ID02 ID02 ID01 ID02 ID04 ID03 ID07 ID04 ID07 ID04 ID07 ID06 ID03 ID03
[29]  ID06 ID05 ID06 ID02 ID02 ID01 ID01 ID04 ID02 ID01 ID03 ID08 ID04 ID08
[43]  ID06 ID05 ID03 ID07 ID08 ID02 ID07 ID05 ID02 ID07 ID04 ID04 ID03 ID08
[57]  ID06 ID08 ID04 ID04 ID08 ID08 ID05 ID02 ID04 ID07 ID08 ID05 ID03 ID04
[71]  ID03 ID06 ID06 ID05 ID03 ID02 ID02 ID04 ID03 ID04 ID03 ID08 ID02 ID05
[85]  ID08 ID08 ID05 ID05 ID08 ID08 ID08 ID06 ID02 ID02 ID02 ID06 ID06 ID07
[99]  ID02 ID07 ID06 ID06 ID03 ID02 ID07 ID05 ID06 ID07 ID01 ID07 ID06 ID04
[113] ID06 ID06 ID01 ID01 ID08 ID07 ID04 ID05 ID03 ID07 ID04 ID07 ID02 ID02
[127] ID02 ID04 ID06 ID03 ID08 ID07 ID02 ID06 ID02 ID05 ID07 ID05 ID04 ID04
[141] ID06 ID08 ID04 ID03 ID06 ID02 ID06 ID03 ID05 ID04 ID03 ID08 ID01 ID01
[155] ID08 ID06 ID08 ID05 ID01 ID04 ID03 ID01 ID06 ID08 ID03 ID08 ID07 ID02
[169] ID01 ID02 ID04 ID03 ID06 ID01 ID03 ID08 ID01 ID05 ID07 ID07 ID02 ID08
[183] ID06 ID07 ID07 ID03 ID04 ID05 ID03 ID08 ID07 ID08 ID05 ID02 ID03 ID03
[197] ID04 ID07 ID07 ID05
raja
Updated on 15-Nov-2021 10:15:29

Advertisements