• Register
0 votes

Problem :

I have been facing below error message and traceback:

Error in FUN(X[[i]], ...) : 
only defined on the data frame with all numeric variables 
5 stop("only defined on the data frame with all numeric variables") 
4 FUN(X[[i]], ...) 
3 lapply(args, function(x) {
    x <- as.matrix(x)
    if (!is.numeric(x) && !is.complex(x)) 
top("only defined on the data frame with all numeric variables") ... 

My only guess is that it is the result of my function code, which is as below:

corr <- function(directory, threshold = 0) {
vect1 <- numeric()
files_list <- list.files(directory, full.names = TRUE)
for (j in 1:332) {
    data <- read.csv(files_list[j])
    good <- complete.cases(data)
    complete_data <- data[good,]
   mysulfate <- complete_data[,2]
    mynitrate <- complete_data[,3]
        if (sum(complete_data) >= threshold) {
            b <- cor(sulfate,nitrate)
            vect1 <- rbind(b)
        else vect1 <- (numeric())

From the above error message and the traceback I guess the error is occurring when my correlation is running on the mysulfate and mynitrate columns. When I tried to run my code on just the first file in my directory, it runs fine with no error messages at all. Any suggestion as to why above error is occurring, and also how to fix it would be helpful to me.

I have tried to coerce my dataset into being numeric as below -

complete_data <- as.numeric(data[good,])

But now I get the different error message back as below :

 "Error: (list) object cannot be coerced to type 'double'"


6 5 3
7,540 points

1 Answer

0 votes

Solution :

You must be counting the number of rows in your good data only and do not try to sum an entire data frame asa below :

if (nrow(complete_data) >= threshold) {
    b <- cor(mysulfate,mynitrate)
    vect1 <- rbind(b)
9 7 4
38,600 points

Related questions

0 votes
2 answers 835 views
Problem : I am facing below error and I am unable to understand the meaning of the error. All my variable names are correct and there are no typing errors. Does anybody faced this issue before any solution on it? My erroneous code : datNewagg <- aggregate (dataNew, by = ... mean) It gives following error : Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Dec 6, 2019 alecxe 7.5k points
1 vote
2 answers 268 views
Problem : I am very new to R. I am facing a issue while entering CurrentDay. I had previously created it as below : Transaction <- function(PnL, Day)   results <- list(a = PnL, b = Day)  return(results) The above PnL and Day are both numeric values. Day ... /MA  return(MAValue) } Please guide me why am I receiving below error? Error in fun(left, right) : non-numeric argument to binary operator.
asked Apr 14 morrisBson 3.2k points
1 vote
1 answer 27 views
Problem : I am trying to understand R and I am very new to Programming as wel. If I try to create the box chart with the use of standard error bars I often face below error message: “Error: ggplot2 doesn't know how to deal with data of class numeric”. Looking for help in quick fixing the above error.
asked May 5 stewart 4k points
0 votes
2 answers 116 views
Problem : I am stuck because of following weired error error in sort.list(y) : 'x' must be atomic for 'sort.list' have you called 'sort' on a list?
asked Nov 15, 2019 peterlaw 6.9k points