Newbie question on creating a function


Just started learning to use R for the first time this week. For an exercise, I want a function to return "Number" if an argument is a number, and "Text" if if it's a text. I thought maybe I could do this with if/else but having trouble figuring it out and thinking I'm approaching it totally wrong. Thanks for the help in advance!

Its straightforward but rather than give you an answer immediately, It would be best if you shared your attempt, so we could see where you are at and good practice for you also in sharing code.
In your forum post use triple backticks to format it correctly.

some code here
1 Like

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.

Hello, thanks for your input..

This is barely what I have... don't know what I'm supposed to put for x= where it says (x=number) and (x=text). Or maybe I'm going about it completely wrong?


funcOne <-function(x) {
    result <-"text"
  } else  {
    result <-"number" }