Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.2k points)

When I run the following code in R then I am not getting any error, but if I run the same code in R shiny, then I am getting the following error:

error 'list' "object cannot be coerced to type 'double' "

In the code, the f2 is the file that is being uploaded by the user, and that file contains only 1 column and multiple rows with 1 word each.

s = vector("list", 1)

#the loop below runs over the length of no of genes all written in different rows

for (i in 1:length(f2[,1])) { s[i] = list({ y = lapply(1:6, function(x) apc[[x]]$Log₂ fold change[apc[[x]]$Name== f2[i,1]] ) unlist(as.numeric(y))

}) }

1 Answer

0 votes
by (107k points)

While observing your error, I think the message might have something to do with the statement unlist(as.numeric(y)):

You can simply try the following code, but this will also throw an error message:

as.numeric(list(c("1", "2"), "3")) # error: 'list' object cannot be coerced to type 'double'

But if you run:

as.numeric(list("1", "2")) 

This will work. 

In last what you can do is save it by switching the commands. First, try to unlist, then type-cast second:

as.numeric(unlist(list(c("1", "2"), "3"))) # works: c(1, 2, 3)

If you are a beginner and want to know more about R the do check out the R programming tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...