Understanding the meaning of [this] code

I was looking at a template code and came across these codes (as seen in attachment) in which I don't understand the outcome of. I just wanted an explaination as to what these codes are resulting in/ the corresponding outcome

The first line converts X.NAME column into a character vector and replaces "-" by "." on each element of the column, the second line replaces empty spaces by "." and the third line converts the column into a factor variable instead of character.

sample_text <- c("name-with-hyphen", "name with spaces")
gsub("-", ".", sample_text)
#> [1] "name.with.hyphen" "name with spaces"
gsub(" ", ".", sample_text)
#> [1] "name-with-hyphen" "name.with.spaces"

Created on 2019-07-11 by the reprex package (v0.3.0)


Thank you so much for your help again!

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