Search code examples
rlistvectoriconv

Using iconv on list?


I have a list of about 1000 character vectors in R that I need to convert to UTF-8. The only tool that I could find for reliable conversions is iconv(), but it only works on character vectors. How can I convert my entire list without smashing it together into a single vector?


Solution

  • OK, I managed to solve this with the "helpful" answers given by the commenters (but thanks nonetheless, since I figured it out anyways). Assuming this is my original list list_1:

    [[1]] 縺薙l縺ッ
    [[2]] 萓ソ蛻ゥ縺ァ縺・
    

    I now use lapply to iterate the function iconv over the entire list, with the arguments for iconv simply listed after a comma inside lapply:

    list_1_iconv <- lapply(list_1, iconv, from = "SHIFT-JIS", to = "UTF-8")
    

    Which yields:

    [[1]] これは
    [[2]] 便利です