How To Use find In R

How To Use find In R

The R language provides an exciting function, the find() function. What is find() in R, and how is it used? To learn these, read this article now.

What is the find() in R?

The find() function returns where we can find a specific object.

Syntax:

find(what, mode, numeric, simple.words)

Parameters:

  • what: a string of characters representing the name of an object.
  • mode: mode to search. The default is “any”.
  • numeric: return positions. The default is FALSE.
  • simple.words: use the whole what argument to search. The default is TRUE.

If the value of the mode argument is not "any", only objects with a mode equal to the mode are searched.

How to use the find() function?

The following is a simple example of how to use the find() function in R.

Example:

find("cor", numeric = TRUE)

Output:

   .GlobalEnv package:stats 
            1             3 

In the above example, we used the find() function to return where we can find the cor() function and its position in that list.

If you want to search for R objects that contain a certain substring, you can use the apropos() function. The syntax of the apropos() function looks like this:

apropos(what, where, ignore.case, mode)

Parameters:

  • what: a string of characters to perform a search for objects.
  • where: return positions. The default is FALSE.
  • ignore.case: ignore case-sensitivity. The default is TRUE.
  • mode: mode to search. The default is “any”.

The apropos() function returns a character vector sorted by name. If where = TRUE, the function returns locations on the search path.

The find() function is always case-sensitive, and the apropos() function can optionally be case-sensitive by setting the value of the ignore.case argument.

Example:

# Ignore case-sensitivity
apropos("GLM", where = TRUE)

# Case-sensitivity
apropos("GLM", ignore.case = FALSE)

Output:

              3               3               3               3               3               3 
          "glm"   "glm.control"       "glm.fit"   "predict.glm" "residuals.glm"   "summary.glm" 

character(0)

In this example, we first use the apropos() function to find all objects that contain the string “GLM” in the name and are case-insensitive. The function results return some objects as above. Then we continue to search, and it’s case-sensitive. The function result returns null.

Summary

We have shown the syntax and how to use the find() in R to search where we can find an R object. You can also use the apropos() function to search all objects in R that contain a specific substring in the name. Thank you for reading.

Maybe you are interested:

Posted in R

Leave a Reply

Your email address will not be published. Required fields are marked *