karyn-h
karyn-h

Reputation: 133

R markdown: Error in FUN(X[[i]], …): cannot coerce type 'symbol' to vector of type 'double'

Even though I can run my code without a problem, when I was trying to knit the markdown file into HTML, these two simple lines of code give me this error:

R markdown: Error in FUN(X[[i]], …): cannot coerce type 'symbol' to vector of type 'double' Calls: ... WithVisible -> eval -> eval -> data.frame -> apply Execution halted

sapply(data, levels)
numdata <- data.frame(lapply(data, as.numeric))

Does anyone know why it happens and how to solve it? I would be very grateful for your help

Upvotes: 0

Views: 514

Answers (1)

karyn-h
karyn-h

Reputation: 133

Thanks @Allan and @quickreaction. The data was given in a Rdata file. So when I opened it, it loads into my Global Environment. It doesn't satisfy the condition that "markdown document is a standalone self-referential code environment"

I solved it by including

write.csv(data,'data.csv')
data<-read.csv('data.csv')

Upvotes: 0

Related Questions