Error in get(as.character(FUN), mode = “function”, envir = envir)

后端 未结 2 1629
温柔的废话
温柔的废话 2020-12-09 17:30

I am new to R, so forgive me if the question is a little silly. I am trying to write a simple while loop for a value function iteration. My function (optim.routine) uses the

相关标签:
2条回答
  • 2020-12-09 18:01

    Many times that error will appear when you previously created an object called "mean" in the R environment. This creates a conflict when calling the function "mean". To stop this error use:

    rm(mean)
    

    This removes the object "mean" from the environment and allows R to call the function "mean".

    0 讨论(0)
  • 2020-12-09 18:04

    I had exactly the same error message when I named a variable with the same name of an existing function in R. I've found this tip here: http://notepad.patheticcockroach.com/2565/a-bad-idea-in-r-using-variables-with-the-same-name-as-existing-functions/ Hope it helps you too. – FraNut Oct 12 at 11:26

    He's right refrain from using variables that might be function names too.

    e.g

    z1<-aggregate(steps ~ interval, data_df, mean)
    mean<-mean(z[,2],na.rm = TRUE)
    

    mean is a variable and a function name passed as an argument to the aggregate function causing a conflict

    0 讨论(0)
提交回复
热议问题