Format column with thousands separator

I have a dataframe with this structure:

df <- data.frame(
  stringsAsFactors = FALSE,
                V1 = c("a", "b", "a", "b", "a", "b", "a"),
                V2 = c(8974L, 8547L, 3695L, 1554L, 3658L, 2541L, 9852L)

Can I modify numbers in column V2 adding "." as separator?

Yes, but then they would be character representations of numbers, and calculations wouldn’t be possible until changing them back. That, along with having succinct column names such as V1 are two of the many reasons to separate the presentation of data from the object used to analyze it, The {gt} package does a nice job of preparing data frames as presentation tables.

If you do want to have character strings instead of numbers, come back and a function can be provided to do that.

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.