Having issues with \N

I'm a newbie literally doing my final test on the Coursea course. My issue is the chunks used on the course never work for me, so I do all the work in RStudio. However, for the dataset I'm working on the column names have a \n in all of them. I tried replacing the \n with an underscore, space and period but it doesn't recognize the column name. Obviously when I run it with the \n, even to try to rename the column name the \ gives an error. Does anyone know how to get around this?

[1] "Company \n(Maker-if known)" "Specific Bean Origin\nor Bar Name" "REF"
[4] "Review\nDate" "Cocoa\nPercent" "Company\nLocation"
[7] "Rating" "Bean\nType" "Broad Bean\nOrigin"

This is small enough to do by hand with

colnames(your_data) <- c("comp","bean","review_date","cocoa_pct","comp_loc","rating","bean_type", "bean_origin")

then do your analysis and when it comes time to make a presentation table use {gt} or another formatter and restore the more descriptive column names.


Awesome didn't know I could use colnames for that, thank you

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.