• Register
0 votes
2.5k views

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())
    }
    return(vect1)
}

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

Please log in or register to answer this question.

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

1 vote
2 answers 945 views
945 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, 2020 morrisBson 3.2k points
0 votes
1 answer 4 views
4 views
Problem: Any solution for this error: Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
2 answers 1.8K views
1.8K 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
0 votes
1 answer 2 views
2 views
Problem: I have a data.frame whose class column is Factor. I'd like to convert it to numeric so that I can use a correlation matrix. How can I convert a Factor column to a numeric column?
asked Mar 30 ummesalma 24.5k points
0 votes
1 answer 698 views
1 vote
1 answer 5 views
5 views
Problem: I&rsquo;m new in data frame. I am doing a relatively simple piece of analysis which I have put into a function, on all the files in a particular folder. I was wondering whether anyone had any tips to help me automate the process on a number of different folders. Firstly, I was wondering whether there ... <- data.frame(A = c(4,2,6,8,1,0),B = (c(3,1,9,11,2,16))) Please help me to fix this.
asked Mar 10 Shovo210 13.3k points
1 vote
1 answer 3 views
3 views
Problem: I&rsquo;m new in data frame. I have a data frame named "mydata" that looks like this this: A B C D 1. 5 4 4 4 2. 5 4 4 4 3. 5 4 4 4 4. 5 4 4 4 5. 5 4 4 4 6. 5 4 4 4 7. 5 4 4 4 I'd like to delete row 2,4,6. For example, like this: A B C D 1. 5 4 4 4 3. 5 4 4 4 5. 5 4 4 4 7. 5 4 4 4 Thanks.
asked Mar 10 Shovo210 13.3k points
1 vote
1 answer 61 views
61 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, 2020 stewart 4k points
1 vote
1 answer 1.5K views
1.5K views
Problem : Currently I am learning the r programming. I am unable to find the answer to below error but I am unable to do so. Currently I have one dataframe it has a column of strings. My task is to count the exact number of characters present in each entry of ... , with no default Error in match.fun(FUN): argument "FUN" is missing, with no default Can someone guide me in fixing above error?
asked Mar 30, 2020 morrisBson 3.2k points
0 votes
1 answer 302 views