I’m trying to appply a function using mapping. However, i’m getting “Caused by error in qr.default()
:
! NA/NaN/Inf in foreign function call (arg 1)” error. There are no NA in the data.
My code:
exp_fit <- function(df){
nls(capacity ~ a*(1 + b)**(year-1995),
data = df,
start = list(a = 100,
b = 0.4))
}
regions.bp = tibble(name = c("EU", "Global"),
list = list("EU",
"Global"),
span = list(1995:2010,
1995:2010))
time.slice.length <- 5:10
for (r in 1:dim(regions.bp)[1]) {
time.span <- regions.bp$span[[r]]
for (t in time.slice.length){
# Get individual time slices for each length t
for (s in 1:(length(time.span)-t+1)){
slice <- time.span[s:(s+t-1)]
temp <- data.bp %>%
filter(region %in% regions.bp$list[[r]],
year %in% slice) %>%
group_by(technology, year) %>%
summarise(capacity = sum(capacity)) %>%
group_by(technology) %>%
nest() %>%
mutate(model.exp = map(data, exp_fit))
}
}
}
Error in mutate()
:
In argument: model.exp = map(data, exp_fit)
.
In group 1: technology = "geothermal"
.
Caused by error in map()
:
In index: 1.
Caused by error in qr.default()
:
NA/NaN/Inf in foreign function call (arg 1)
I tried to omit NA values and tried a loop instead of map function. However it returns the same error.
Gokul Prakash K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.