Error: unexpected symbol %>%

I've been trying to use this code and keep getting the error: Error: unexpected symbol in:
"WtLoss <- InData %>% pivot_longer(Al:S, names_to = "Trt", values to". Here's the code, does anyone have any suggestions?
InData <- read.csv("~/Data/ex9-13.txt", quote="'")
library(tidyverse)
WtLoss <- InData %>%
pivot_longer(Al:S, names_to = "Trt", values to= "Loss") %>% mutate(Trt = as_factor(Trt)) %>%
mutate(Trt = fct relevel(Trt, "S")) str(WtLoss)
table(WtLoss$Trt)

Try moving this to the top line; unless {dplyr} or {magrittr} have been loaded, the %>% operator will not be recognized.

Thanks, I tried that but still got the same error. I have dplyr and magrittr installed but added library(dplyr) to the code and it still has the same error

How about the leading quotemark?

See the FAQ: How to do a minimal reproducible example reprex for beginners.

That did it I can't believe I missed it, thanks so much!

1 Like

Delimiters, symbols like quotemarks, that come in pairs often throw this kind of error.

This topic was automatically closed 7 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.