![]() |
VOOZH | about |
In this article, we will see how to Access variables of a data frame in R Programming Language.
attach() function in R Language is used to access the variables present in the data framework without calling the data frame.
Syntax: attach(data, pos)
Parameters:
- data: data frame
- pos: position of database
Example: Accessing variables of a data frame in R using attach() function
Output:
1 2 3 4 5Here in the above code, we have created a data framework and assigned a value to it, when we tried to return value an error occurred. Then we use the attach function and returned value of x1.
detach() function is used to remove the attachment in data framework that was made by attach() function.
Syntax: detach(data, unload)
Parameters:
- data: data frame
- unload: boolean value
Example: Accessing variables of a data frame in R using detach() Function
Output:
Error in as.tbl(data) : could not find function "as.tbl"
Here in the above code, we have installed a dplyr package and used its function as.tbl. Then we detach the package and try to use the function again, and an error occurred. detach functions are used to unpack the libraries which were added to the library.