I am trying to convert Hexadecimal grid data into a decimal value. I am trying different functions for that but it is not working?

# How to convert Hexadecimal values to decimal in dataframe?

Hi @Ronak

It would be helpful if you can share the grid that you have referred to and the output that you are expecting. Also, please provide any additional information that might help us.

Warm Regards,

Pritish

Looks like there's a function for that in the broman package:

I use the same function its working for single value. but when i try to apply on Column or grid its not working.

If you need more specific help, please provide a proper **REPR**oducible **EX**ample (reprex) illustrating your issue.

As you can see in image there is a six Column which contain hexadecimal values. i want to convert all of them in Decimal. I want to know how to convert all the Values of DataFrame into Decimal?

The reason you're being asked for a reprex, or for some non-image source for your data is that it's much easier to help you if we have the code. Here's one solution using the aforementioned `hex2dec()`

function, and `mutate_all()`

from dplyr.

Note that column names that start with numbers are not syntactically valid in R, so they have to be surrounded by backticks.

```
library(broman)
hexdf <- tibble::tribble(
~`1`, ~`2`, ~`3`,
"1A", "15", "18",
"16", "1F", "13",
"1D", "19", "1B"
)
dplyr::mutate_all(hexdf, hex2dec)
#> # A tibble: 3 x 3
#> `1` `2` `3`
#> <int> <int> <int>
#> 1 26 21 24
#> 2 22 31 19
#> 3 29 25 27
```

^{Created on 2019-12-02 by the reprex package (v0.3.0.9001)}

To "save" the output, you can create a new data frame/object by assigning it a new name, or you can overwrite the hexdf object you created at the beginning.

i have 3 column that i want to convert into hexadecimal. all the column contain more than 500 values. so how can i convert that using this function? i want to know that only. i am also using same function hextodec() .i can convert one value using this. but i want to know how can i convert column values using the same function?

mara's last post showed how to convert entire columns. If your data frame is named Hex, your code will look like

```
library(broman)
library(dplyr)
NewDF <- mutate_all(Hex, hex2dec)
```

Be aware that the hex2dec function expects the hex numbers to be characters, as shown in mara's post.

I do not know if the hex2dec function handles non-integer input.

I also notice in your example data that none of the digits are in the range A-F, though you have hundreds of digits. That is very odd.

I try this. it converts the Integer into decimal but not convert the grid that I show here as example data. It shows this type of error.

**NewDF <- mutate_all(a, hex2dec)**

Error:

**Error in UseMethod("tbl_vars") :**

**no applicable method for 'tbl_vars' applied to an object of class "character"**

Could you please turn this into a self-contained reprex (short for **repr**oducible **ex**ample)?

Currently, we can't reproduce what you're seeing — or we'd have to go through and manually try to type in the values in the image, and, even then, we can't know exactly the steps you're taking that are leading to that error message.

```
install.packages("reprex")
```

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

## What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

```
reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")
```

For pointers specific to the community site, check out the reprex FAQ.