我正在尝试将数据导出到csv文件。我的数据框主要由中文字符串组成。我使用瑞典语作为默认语言在Win10计算机上使用带有IRkernel的Jupyter笔记本。
语言环境设置为中文:
ys.setlocale("LC_ALL", 'chs')
导出为csv的行:
write.table(TEST, file = "C:/Users/sxuep/Google Drive/Chengtou_
Copy/build/output/TEST.csv"
我收到的错误消息:
Error in write.table(TEST, file = "C:/Users/sxuep/Google Drive/Chengtou_
Copy/build/output/TEST.csv", : 'translateChar' must be called on a CHARSXP
Traceback:
1. write.csv(TEST, file = "C:/Users/sxuep/Google Drive/Chengtou_
Copy/build/output/TEST.csv")
2. eval.parent(Call)
3. eval(expr, p)
4. eval(expr, p)
5. write.table(TEST, file = "C:/Users/sxuep/Google Drive/Chengtou_
Copy/build/output/TEST.csv",
. col.names = NA, sep = ",", dec = ".", qmethod = "double")
我试过" dput(head(test))"我的文本输出乱码:
structure(list(֤ȯ´úÂë = c("122402.SH", "101454021.IB", "101558031.IB",
"122217.SH", "101474004.IB", "101575002.IB"), ֤ȯ¼ò³Æ = c("15³Ç½¨01",
"14Éî¸ßËÙMTN001", "15Éî¸ßËÙMTN001", "12ÓåË®Îñ", "14»¦³Ç¿ØMTN001",
"15»¦³Ç¿ØMTN001(3ÄêÆÚ)"), ·¢Ðжî = c("58", "10", "9", "15", "20",
"15"), ծȯÓà¶î = c("58", "10", "9", "15", "20", "15"), ÆðÏ¢ÈÕÆÚ = c("2015-
07-20",
"2014-05-08", "2015-08-18", "2013-01-29", "2014-04-22", "2015-04-23"
), µ½ÆÚÈÕÆÚ = c("2022-07-20", "2017-05-08", "2018-08-18", "2018-01-29",
"2019-04-22", "2018-04-23"), ծȯÆÚÏÞ = c("7", "3", "3", "5",
"5", "3"), ƱÃæÀûÂÊ = c("4.4", "5.5", "3.95", "5.12", "6.28",
"4.59"), ÀûÂÊ˵Ã÷ = c("20150720-20200719,ƱÃæÀûÂÊ:4.40%;20200720-
20220719,ƱÃæÀûÂÊ:4.40%+Éϵ÷»ùµã",
"5.5%", "3.95%", "5.12%", "6.28%", "4.59%"), ½»Ò×ƽ̨ =
c("¾º¼Û+¹Ì¶¨ÊÕÒæƽ̨",
NA, NA, "¾º¼Û+¹Ì¶¨ÊÕÒæƽ̨", NA, NA), Ê¡·Ý = c("±±¾©", "¹ã¶«Ê¡",
"¹ã¶«Ê¡", "ÖØÇì", "ÉϺ£", "ÉϺ£"), WindÐÐÒµÃû³Æ = c("·¿µØ²ú",
"¹¤Òµ", "¹¤Òµ", "¹«ÓÃÊÂÒµ", "·¿µØ²ú", "·¿µØ²ú"), Ô±¹¤×ÜÊý = c("2613",
"5254", "5254", "5188", "2144", "2144"), ×¢²á×ʱ¾ = c("156704",
"218077.0326", "218077.0326", "480000", "252957.5634", "252957.5634"
), ÌØÊâÌõ¿î = c("»ØÊÛ,µ÷ÕûƱÃæÀûÂÊ", NA, NA, NA, NA, NA), ÌØÊâÌõ¿îÎÄ×Ö =
c("»ØÊÛ:·¢ÐÐÈË·¢³ö¹ØÓÚÊÇ·ñÉϵ÷±¾ÆÚծȯƱÃæÀûÂʼ°Éϵ÷·ù¶ÈµÄ¹«¸æºó,Ͷ×ÊÕßÓÐȨѡÔñÔ
Ú±¾ÆÚծȯµÚ5¸ö¼ÆÏ¢Äê¶ÈµÄͶ×ÊÕß»ØÊ۵ǼÇÆÚÄÚ½øÐеǼÇ,½«Æä³ÖÓеı¾ÆÚծȯȫ²¿»ò²¿·Ö°´ÃæÖµ»ØÊÛ¸ø·¢ÐÐÈË.±¾ÆÚծȯµÚ5¸ö¼ÆÏ¢Äê¶È¸¶Ï¢ÈÕ¼´Îª»ØÊÛÖ§¸¶ÈÕ,·¢ÐÐÈ˽«°´ÕÕÉϺ£Ö¤È¯½»Ò×ËùºÍծȯµÇ¼Ç»ú¹¹Ïà¹ØÒµÎñ¹æÔòÍê³É»ØÊÛÖ§¸¶¹¤×÷.Ͷ×ÊÕßÄâÐÐʹ²¿·Ö»òÈ«²¿»ØÊÛÑ¡ÔñȨ,ÐëÓÚ¹«Ë¾·¢³ö¹ØÓÚÊÇ·ñÉϵ÷±¾ÆÚծȯƱÃæÀûÂÊÒÔ¼°Éϵ÷·ù¶ÈµÄ¹«¸æÖ®ÈÕÆð5¸ö½»Ò×ÈÕÄÚ½øÐеǼÇ,ÏàÓ¦µÄ¹«Ë¾Õ®È¯Æ±Ãæ×ܶ±»¶³½á½»Ò×;ÈôͶ×ÊÕßδ×öµÇ¼Ç,ÔòÊÓΪ·ÅÆú»ØÊÛÑ¡ÔñȨ,¼ÌÐø³ÖÓб¾ÆÚծȯ.£»µ÷ÕûƱÃæÀûÂÊ:·¢ÐÐÈËÓÐȨ¾ö¶¨ÊÇ·ñÔÚ±¾ÆÚծȯ´æÐøÆڵĵÚ5ÄêÄ©Éϵ÷±¾ÆÚծȯºó2ÄêµÄƱÃæÀûÂÊ.·¢ÐÐÈ˽«ÓÚ±¾ÆÚծȯµÚ5¸ö¼ÆÏ¢Äê¶È¸¶Ï¢ÈÕÇ°µÄµÚ20¸ö½»Ò×ÈÕ,ÔÚÖйúÖ¤¼à»áÖ¸¶¨µÄÐÅÏ¢Åû¶ýÌåÉÏ·¢²¼¹ØÓÚÊÇ·ñÉϵ÷±¾ÆÚծȯƱÃæÀûÂÊÒÔ¼°Éϵ÷·ù¶ÈµÄ¹«¸æ.Èô·¢ÐÐÈËδÐÐʹÀûÂÊÉϵ÷Ȩ,Ôò±¾ÆÚծȯºóÐøÆÚÏÞƱÃæÀûÂÊÈÔά³ÖÔÓÐƱÃæÀûÂʲ»±ä.",
NA, NA, NA, NA, NA), ֤ȯȫ³Æ = c("±±¾©³Ç½¨Í¶×Ê·¢Õ¹¹É·ÝÓÐÏÞ¹«Ë¾2015Ä깫˾ծȯ(µÚÒ»ÆÚ)",
NA, "ÉîÛÚ¸ßËÙ¹«Â·¹É·ÝÓÐÏÞ¹«Ë¾2015Äê¶ÈµÚÒ»ÆÚÖÐÆÚƱ¾Ý", "ÖØÇìË®Îñ¼¯ÍŹɷÝÓÐÏÞ¹«Ë¾2012Ä깫˾ծȯ",
"ÉϺ£³ÇͶ¿Ø¹É¹É·ÝÓÐÏÞ¹«Ë¾2014Äê¶ÈµÚÒ»ÆÚÖÐÆÚƱ¾Ý", "ÉϺ£³ÇͶ¿Ø¹É¹É·ÝÓÐÏÞ¹«Ë¾2015Äê¶ÈµÚÒ»ÆÚÖÐÆÚƱ¾Ý(Æ·ÖÖÒ»)"
), ×ʽðÓÃ; = c("¹«Ë¾ÄâʹÓñ¾´Îļ¼¯×ʽðÖÐ28.15ÒÚÔª³¥»¹¹«Ë¾Õ®Îñ,ÒÔ½µµÍ²ÆÎñ·ÑÓò¢ÓÅ»¯Õ®Îñ½á¹¹.±¾´Î¹«¿ª·¢Ðй«Ë¾Õ®È¯Ä¼¼¯×ʽðµ½Î»Ö®Ç°,·¢ÐÐÈ˽«¸ù¾Ý¹«Ë¾Õ®ÎñµÄʵ¼ÊÇé¿öÒÔ×Ô³ï×ʽðÏÈÐг¥»¹,²¢ÔÚļ¼¯×ʽðµ½Î»Ö®ºóÓèÒÔÖû».±¾´ÎÄâ³¥»¹µÄ¹«Ë¾Õ®ÎñÃ÷ϸÈçÏÂ:\r\n´û¿îµ¥Î»\tÄâ³¥»¹½ð¶î(ÒÚÔª)\r\nÎå¿ó¹ú¼ÊÐÅÍÐÓÐÏÞ¹«Ë¾\t8\r\nÖйú½ð¹È¹ú¼ÊÐÅÍÐÓÐÏÞÔðÈι«Ë¾\t6\r\n½¨ÐÅÐÅÍÐÓÐÏÞÔðÈι«Ë¾\t4.5\r\nÐÂʱ´úÐÅÍйɷÝÓÐÏÞ¹«Ë¾\t6.40\r\nлªÐÅÍйɷÝÓÐÏÞ¹«Ë¾\t2.80\r\nÎ÷²ØÐÅÍÐÓÐÏÞ¹«Ë¾\t0.45\r\n¹«Ë¾ÄâʹÓñ¾´Îļ¼¯×ʽðÖÐ29.85ÒÚÔªÓÃÓÚ²¹³äÁ÷¶¯×ʽð,Âú×㹫˾ÔËÓªÐèÇó.",
NA, "¹«Ë¾±¾´Î·¢ÐÐÖÐÆÚƱ¾Ýļ¼¯×ʽð9ÒÚÔªÖ÷ÒªÓÃ;Ϊ³¥»¹ÒøÐнè¿î¼°²¹³ä¼¯ÍÅÓªÔË×ʽð,ÆäÖÐ8ÒÚÔªÓÃÓÚ³¥»¹±¾¹«Ë¾¼°¿Ø¹É×Ó¹«Ë¾ÒøÐнè¿î,1ÒÚÔªÓÃÓÚ²¹³ä±¾¹«Ë¾ÓªÔË×ʽð.",
"±¾ÆÚծȯµÄļ¼¯×ʽð¿Û³ý·¢ÐзÑÓúó,È«²¿ÓÃÓÚ²¹³ä¹«Ë¾µÄÓªÔË×ʽð,ÉÏÊö°²ÅžßÓбØÒªÐԺͺÏÀíÐÔ.·¢ÐÐÈË×÷ΪˮÎñÐÐÒµÖеĴóÐÍÆóÒµ,¾ßÓÐÒ»´ÎÐÔͶ×ʹæÄ£´ó,Ͷ×Ê»ØÊÕÖÜÆÚ³¤µÄÌصã.Ë®ÎñÐÐÒµ×÷ΪµØÇøµÄ»ù´¡ÉèÊ©,Æ佨Éè¹æÄ£Ó¦Âú×ã¸ÃµØÇøÒ»¶¨Ê±ÆÚµÄÐèÒª,Êʶȳ¬Ç°½¨Éè.¼øÓÚË®ÎñÐÐÒµÊôÓÚ×ʱ¾Ãܼ¯ÐÍÐÐÒµ,¹«Ë¾×ʱ¾ÐÔÖ§³ö½Ï´ó,ÆäÖÐÒԹ̶¨×ʲúͶ×ÊΪÖ÷,Ö÷ÒªÓÃÓÚÀ©½¨»òн¨´óÐ͹©Ë®,ÎÛË®´¦Àí³§¼°ÅäÌ×ÉèÊ©,ÒÔ¼°¼¼Êõ¸ÄÔì,½¨Öþ¹¤³ÌµÈ,ÍùÍùÐèÒªÊýÒÔÒڼƵÄ×ʽðͶÈë.¹«Ë¾½üÄêÀ´²»¶Ï¼Ó´óÁËÒÔ×ÔÀ´Ë®¹©Ó¦ºÍÎÛË®´¦ÀíΪºËÐÄÒµÎñÁìÓòµÄͶ×ʽ¨Éè,ÈÕ³£ÓªÔË×ʽðÐèÇóÁ¿²»¶ÏÔö¼Ó.ÔÚ×¥ºÃÉÏÊöÏîÄ¿½¨ÉèµÄͬʱ,±¾¹«Ë¾Ò²½«Ñ°Çóͨ¹ýÊÕ¹º¼æ²¢²ßÂÔ²»¶ÏÀ©´óÒµÎñ¹æÄ£,Ìá¸ßÊг¡Õ¼ÓÐÂÊ.Òò´Ë²¹³äÓªÔË×ʽðÊÇÊ®·Ö±ØÒªµÄ,½«ÏÔÖøÌáÉý¹«Ë¾µÄ¿¹·çÏÕÄÜÁ¦,ÓÅ»¯²ÆÎñ½á¹¹,Ö§³Ö¹«Ë¾µÄ³¤ÆÚ·¢Õ¹.",
"·¢ÐÐÈ˱¾´ÎÖÐÆÚƱ¾Ý×¢²á¶î¶È20ÒÚÔª,½«Ò»´ÎÐÔ·¢ÐÐÍê±Ï,ļ¼¯×ʽðÈ«²¿ÓÃÓÚ³¥»¹¹«Ë¾±¾²¿µÄ¶ÌÆÚÒøÐнè¿î,ÓÅ»¯¹«Ë¾Õ®Îñ½á¹¹.",
"±¾´Îļ¼¯×ʽð¼Æ»®³¥»¹¹«Ë¾±¾²¿µÄÒøÐнè¿î."), Ö¤¼à»áÐÐÒµ·ÖÀà = c("·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ",
NA, "½»Í¨ÔËÊä¡¢²Ö´¢ºÍÓÊÕþÒµ-Ìú·ÔËÊäÒµ-Ìú·ÔËÊäÒµ-Ìú·ÔËÊäÒµ",
"µçÁ¦¡¢ÈÈÁ¦¡¢È¼Æø¼°Ë®Éú²úºÍ¹©Ó¦Òµ-Ë®µÄÉú²úºÍ¹©Ó¦Òµ-Ë®µÄÉú²úºÍ¹©Ó¦Òµ-Ë®µÄÉú²úºÍ¹©Ó¦Òµ",
"·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ", "·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ-·¿µØ²úÒµ"
), windÐÐÒµ·ÖÀà = c("·¿µØ²ú--·¿µØ²ú¢ò--·¿µØ²ú¹ÜÀíºÍ¿ª·¢--·¿µØ²ú¿ª·¢",
NA, "¹¤Òµ--ÔËÊä--½»Í¨»ù´¡ÉèÊ©--¹«Â·ÓëÌú·", "¹«ÓÃÊÂÒµ--¹«ÓÃÊÂÒµ¢ò--Ë®Îñ¢ó--Ë®Îñ",
"·¿µØ²ú--·¿µØ²ú¢ò--·¿µØ²ú¹ÜÀíºÍ¿ª·¢--·¿µØ²ú¿ª·¢", "·¿µØ²ú--·¿µØ²ú¢ò--·¿µØ²ú¹ÜÀíºÍ¿ª·¢--·¿µØ²ú¿ª·¢"
), ÉêÍòÐÐÒµ·ÖÀà = c("·¿µØ²ú--·¿µØ²ú¿ª·¢", NA, "½»Í¨ÔËÊä--¸ßËÙ¹«Â·",
"¹«ÓÃÊÂÒµ--Ë®Îñ", "·¿µØ²ú--·¿µØ²ú¿ª·¢", "·¿µØ²ú--·¿µØ²ú¿ª·¢"),
·¢Ðлú¹¹ = c("SH", "IB", "IB", "SH", "IB", "IB"), ծȯÀàÐÍ = c(NA,
"MTN", "MTN", NA, "MTN", "MTN"), Ö¤¼à»áÐÐÒµ = c("·¿µØ²úÒµ",
"NA", "Ìú·", "¹©Ó¦", "·¿µØ²úÒµ", "·¿µØ²úÒµ"), windÐÐÒµ = c("·¿µØ²ú",
"NA", "¹¤Òµ", "¹«ÓÃÊÂÒµ", "·¿µØ²ú", "·¿µØ²ú"), ÉêÍòÐÐÒµ = c("·¿µØ²ú",
"NA", "¸ßËÙ¹«Â·", "¹«ÓÃÊÂÒµ", "·¿µØ²ú", "·¿µØ²ú")), .Names = c("֤ȯ´úÂë",
"֤ȯ¼ò³Æ", "·¢Ðжî", "ծȯÓà¶î", "ÆðÏ¢ÈÕÆÚ", "µ½ÆÚÈÕÆÚ", "ծȯÆÚÏÞ",
"ƱÃæÀûÂÊ", "ÀûÂÊ˵Ã÷", "½»Ò×ƽ̨", "Ê¡·Ý", "WindÐÐÒµÃû³Æ", "Ô±¹¤×ÜÊý",
"×¢²á×ʱ¾", "ÌØÊâÌõ¿î", "ÌØÊâÌõ¿îÎÄ×Ö", "֤ȯȫ³Æ", "×ʽðÓÃ;",
"Ö¤¼à»áÐÐÒµ·ÖÀà", "windÐÐÒµ·ÖÀà", "ÉêÍòÐÐÒµ·ÖÀà", "·¢Ðлú¹¹",
"ծȯÀàÐÍ", "Ö¤¼à»áÐÐÒµ", "windÐÐÒµ", "ÉêÍòÐÐÒµ"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
我的会话信息:
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] wordcloud_2.5 RColorBrewer_1.1-2 jiebaR_0.9.1 jiebaRD_0.1
[5] bindrcpp_0.2 haven_1.1.0 readxl_1.0.0 stringr_1.2.0
[9] dplyr_0.7.2 ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.12 compiler_3.4.1 cellranger_1.1.0
[4] plyr_1.8.4 bindr_0.1 forcats_0.2.0
[7] tools_3.4.1 digest_0.6.12 uuid_0.1-2
[10] jsonlite_1.5 evaluate_0.10.1 tibble_1.3.4
[13] gtable_0.2.0 pkgconfig_2.0.1 rlang_0.1.2
[16] IRdisplay_0.4.4 IRkernel_0.8.8.9000 repr_0.12.0
[19] grid_3.4.1 glue_1.1.1 R6_2.2.2
[22] pbdZMQ_0.2-6 magrittr_1.5 scales_0.5.0
[25] assertthat_0.2.0 colorspace_1.3-2 labeling_0.3
[28] stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3
[31] slam_0.1-40 crayon_1.3.2
我不理解错误信息。