R change character encoding of a character vector <p>I read in two data frames from two different excel spreadsheets using openxlsx::read.xlsx. I want to get the common column names. With</p> <pre><code>intersect(colnames(nutrients), colnames(req.EAR)) </code></pre> <p>the output is </p> <pre><code>[1] "carbohydrate_g" "calcium_mg" "iron_mg" "magnesium_mg" "phosphorus_mg" "zinc_mg" "vit_c_mg" [8] "thiamin_mg" "riboflavin_mg" "niacin_mg" "vit_b6_mg" "folate_µg" "vit_b12_µg" "vit_a_rae_µg" [15] "vit_e_mg" </code></pre> <p>a common element - vit_d_μg - doesn't show up in the intersection. I suspected this was because in both spreadsheets, element that contain μ are coded as UTF-8 while the rest are "unknown".</p> <p>The cause of all of this I think is the mu (μ) in the column name. I originally thought this was due to the fact that element names with mu in it were encoded as UTF-8 while the others were "unknown".</p> <p>The real reason is that there are two UTF-8 characters that look like mu. At this website ([<a href="http://www.fileformat.info/info/charset/UTF-8/list.htm]" rel="nofollow">http://www.fileformat.info/info/charset/UTF-8/list.htm]</a></p> <pre><code>GREEK SMALL LETTER MU (U+03BC) looks like μ. MICRO SIGN (U+00B5) looks like µ. </code></pre> <p>Someone (probably me) made a mistake in adding the mu to the spreadsheet.</p>