Convert String to Integer in R Programming – strtoi() Function

strtoi() function in R Language is used to convert the specified string to integers.

Syntax: strtoi(x, base=0L)

Parameters:
x: character vector
base: integer between 2 and 36 inclusive, default is 0

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strtoi function
  
# Initializing some string vector
x <- c("A", "B", "C")
y <- c("1", "2", "3")
  
# Calling strtoi() function
strtoi(x, 16L)
strtoi(y)

chevron_right


Output :

[1] 10 11 12
[1] 1 2 3

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strtoi function
  
# Calling strtoi() function over
# some specified strings
strtoi(c("0xff", "023", "567"))
strtoi(c("ffff", "FFFF"), 16L)
strtoi(c("246", "135"), 8L)

chevron_right


Output:

[1] 255  19 567
[1] 65535 65535
[1] 166  93
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.