I'm trying to change all dataset to replace special symbols and characters, but I want to use dplyr to perform that, and I did not find an answer. When I say "special", I mean symbols typical found in foreign languages, such as Portuguese.
ds <- data.frame(group=c("american", "canadian"),
queçtão.1=rnorm(n=50,mean=100,sd=15),
queçtão.2=rnorm(n=50, mean=1500, sd=300),
queçtão.18=rnorm(n=50, mean=5, sd=2))
to something like
quectao1
quectao2
quectão18
Why my question:
A forum member helped me to use dplyr to gather variables and summarise its results, but it's not working in variables with special symbols:
set.see(123)
ds <- data.frame(group=c("american", "canadian"),
queçtão.1=rnorm(n=50,mean=100,sd=15),
queçtão.2=rnorm(n=50, mean=1500, sd=300),
queçtão.18=rnorm(n=50, mean=5, sd=2))
ds %>%
group_by(group) %>%
summarise_at(vars(queçtão.1,queçtão.2,queçtão.18),funs(mean, sd)) %>%
gather(key, val, queçtão.1_mean:queçtão.18_sd) %>%
separate(key, into = c('key1', 'key2')) %>%
unite(group, group, key2) %>%
spread(group, val)
Error: Duplicate identifiers for rows (1, 7), (5, 11), (3, 9), (2, 8), (6, 12), (4, 10)
In addition: Warning message:
Expected 2 pieces. Additional pieces discarded in 12 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].