error message in R

annual high temperature (txx) averaged over the period 2080-2100 in scenario (RCP2.6)

futurehigh<- function(new_city,ex){
for (city in ex)
rcp2.6<- ex%>%filter(city==new_city)%>%filter(year>=2080&year<=2100)%>%filter(scenario=="RCP2.6")

average2.6=mean(rcp2.6$txx)

returen(average)
if(!ex$city){
print("city not exist")
}
}
where is the error of function , can help me please ?

return is misspelled, for a start.

What does the error message say?

I write it correctly in the program

the error massage say that the city you enter doesn't found in the data

Can you provide a reproducible example?

I dont understand what is related to my question

@williaml asked for a reproducible example so that we can run the same data and code that you run when you get an error. You have already provided the function code. Now make a small data set that you know produces the error. Filter you original data to have, say, only two cities, a few years, and one scenario. If that data set is named DF, run the code

dput(DF)

and post the output here. Place a line with three back ticks just before and after the output, like this
```
output of dput() function
```
We should the be able to run the data you posted through the futurehigh function and get the same error you are getting.

1 Like

we can use this code

y<- function(city,ex){

if(!missing("city"))

stop("This is an error massage ")

}

missing() says whether the user of the function passed in the argument city. Since you have a not sign, if they did pass in the argument you get an error message. Doesn't seem likely that's what you want.

If you follow the suggestions from @williaml and @FJCC, even though it's a little bit of work, folks will be able to give you much better help.

1 Like

iam new in r can i contact via another application

Follow the link @williaml provided. It's intended to help beginners post information in a way that is most likely to get help.

where is the link ? @stratz

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.