问题
I have imported an Excel (xlsx) file using the readxl
package in R
. One of the columns, labeldata
, that is imported into R
contains labels for other data contained in the file, so it consists of character data such as ≥65 years old
. When I print this labeldata
to the console the value for "greater than or equal to 65 years old"
is properly displayed as ≥65 years old
. However, when I try to combine this column with other columns (using cbind
or other methods), the greater than or equal to sign (≥
) is converted to an equal sign (=
). I tried to dput
the labeldata
object to a text file, to include in this post, but when I do so, the greater than or equal sign is converted to an equal sign there as well.
Here's the best toy example I can come up with that kind of explains what I'm seeing:
labeldata="≥ 65 years"
print(labeldata)
[1] "= 65 years"
The problem with this example, of course, is that I've simply typed in the label and could avoid the conversion issue by typing in labeldata="\u2265 65 years"
, but in my real work, I'm not typing in this infomration, but importing the data from Excel.
I'm guessing this is some sort of encoding issue, but is there any way to prevent the label from converting to an equal sign and to preserve the original label?
Updated relevant information
I am using Windows 10 x64 OS, with R Studio, but I've verified the problem exists within just R. I have this problem in R 3.2.3 and R 3.6.1.
I've also noticed that while this works without any problem:
labeldata = "\u2265 65 years"
labeldata
[1] "≥ 65 years"
Converting to a dataframe causes the problem to reappear:
labeldata = "\u2265 65 years"
labeldata
[1] "≥ 65 years"
data.frame(labeldata)
labeldata
1 = 65 years
来源:https://stackoverflow.com/questions/58258790/r-greater-than-or-equal-to-character-converts-to-equal-sign