I have a character vector that I want separated into different columns where the .
is the deliminator, but the stringr::str_split()
, strsplit()
, and tidyr::split
functions don't identify .
as a deliminator, and instead give blanks instead.
test <- data.frame(data = paste(letters, '.', 1:length(letters), '.', letters, sep = ''))
str_split(string = test$data, pattern = '.', simplify = T)
separate(data = test, col = 'data', into = c('letter', 'number'), sep = '.')
strsplit(x = test$data, split = '.')
Using stringr::str_replace_all()
also results in all characters within the string getting replaced as well:
str_replace_all(string = test$data, pattern = '.', replacement = '-')
My questions are:
- Is there a technical (e.g. computer science?) reason why it does this (just for my own curiosity)? This is so I can avoid doing this in the future and give a reason for it when I teach?
- How do I solve the issue of changing
.
to another character? Because I'm in the problem now and not sure how to resolve it...