To clear some messy data, I would like to start using the%>% pipes, but I cannot get the R code, if gsub () is not at the beginning of the channel, it should appear later (Note: this question is not related to proper import, but with data cleaning)
A simple example:
df <- cbind.data.frame(A= c("2.187,78 ", "5.491,28 ", "7.000,32 "), B = c("A","B","C"))
Column A contains characters (in this case, numbers, but it can also be a string) and must be cleared. Steps
df$D <- gsub("\\.","",df$A) df$D <- str_trim(df$D) df$D <- as.numeric(gsub(",", ".",df$D))
You can easily skip this
df$D <- gsub("\\.","",df$A) %>% str_trim() %>% as.numeric(gsub(",", ".")) %>%
The problem is the second gsub, because it requests Input ... which is actually the result of the previous line.
Please, can someone explain how to use functions like gsub () further down the pipeline? Thank you very much!
: R 3.2.3, Windows