[R] Chinese characters encoding problem with XML
windspeedo at qq.com
Wed Dec 31 02:29:02 CET 2008
XML is a good tool reading data from web within R. But I wonder how could get the encoding correctly.
url <- 'http://www.szitic.com/docc/jz-lmzq.html'
xml <- htmlTreeParse(url, useInternal=TRUE)
q <- "//tbody/tr/td"
dat <- unlist(xpathApply(xml, q, xmlValue))
df <- as.data.frame(t(matrix(dat, 4)))
The first column of df is dates in Chinese. dt is one of the Chinese dates.
When I copied the content of dt into the email, it become the following:
Indeed in R, it looks like:
and the color of the numbers differs a little.
 "LC_COLLATE=Chinese (Simplified)_People's Republic of China.936;LC_CTYPE=Chinese (Simplified)_People's Republic of China.936;LC_MONETARY=Chinese (Simplified)_People's Republic of China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_People's Republic of China.936"
R version 2.8.0 (2008-10-20)
Windows Vista Basic, Simplified Chinese edition.
There is no problem using Chinese characters in R codes.
I wonder how could get the Chinese characters with XML. Or is there any methods which could help me convert the encoding of characters from UTF-8 to unicode in R?
More information about the R-help