• 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

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

0 votes
2 answers 1.4K 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 688 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 306 views
1 vote
1 answer 42 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.1K 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 82 views
0 votes
1 answer 713 views
0 votes
2 answers 149 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
0 votes
1 answer 1.1K views
Problem : I am learning to work with neural networks in R. As a learning tutorial I am using the following problem over at Kaggle: https://www.kaggle.com/c/titanic This problem is specifically designed for people who want to learn and please note there is no reward ... Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments Can anyone help in resolving my issue?
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 219 views
Problem : I want to use the TraMineR's (version 1.8.4) seqdef-funciton to define the sequence object, however I always face the following error message which is completely senseless to me: Error in row.names<-.data.frame(*tmp*, value = value) : invalid 'row. ... tried running it after re-labeling the states without "-", but it does not affect the error. Does someone knows what causes this error?
asked Dec 6, 2019 alecxe 7.5k points