How can I trim leading and trailing white space?

后端 未结 13 1499
北海茫月
北海茫月 2020-11-22 03:53

I am having some troubles with leading and trailing white space in a data.frame.

For example, I like to take a look at a specific row in a data.fra

13条回答
  •  不知归路
    2020-11-22 03:59

    myDummy[myDummy$country == "Austria "] <- "Austria"
    

    After this, you'll need to force R not to recognize "Austria " as a level. Let's pretend you also have "USA" and "Spain" as levels:

    myDummy$country = factor(myDummy$country, levels=c("Austria", "USA", "Spain"))
    

    It is a little less intimidating than the highest voted response, but it should still work.

提交回复
热议问题