I am importing data from Excel. I am using the package readxl to read the data. I have a column of data with both numbers as well as percentage values. Therefore, I want to import this column of data as text.
I used the instructions on the package documentation page how to define column types when importing data. However, even when the data is imported as text, it still converts the percentage to a number.
This is an example of what the data look like the field I am having trouble with:
data <- c(3200, 100%, 100, 100%) The data frame after the import is showing that it is a character and not numeric. The results I expect would be the same as the vector above. However, what I am seeing is as follows:
output_after_import <- c(3200, 1, 100, 1) When looking at the data in Excel, when I change the data type from "General" to "Text," the same problem occurs as shown in "output_after_import."
colClassreadxlas much as it is in Excel. In Excel (as much as in R), what you see (100and100%) is just a representation of the data. Internally, it is being stored numerically (100and1.0). So your issue isn't with R, it's with Excel. As Mike suggested, I believe your best step forward at this point is to tell Excel what format you want it stored as. (Usingopenxlsxproduces the same results. Perhaps you can find a way to read what Excel thinks the formatting is for each cell, and adjust accordingly. Idk how yet.)