Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ANSWER IN R CODING LANGUAGE ONLY. Write a function is_attribute( ) that takes as input: 1: , an object, and at , a character vector
ANSWER IN R CODING LANGUAGE ONLY.
Write a function is_attribute( ) that takes as input: 1: , an object, and at , a character vector of length 1 (AKA a string). If at is an attribute of x , return TRUE , otherwise output FALSE . If an invalid input is passed for at , throw an error of your choice. For example: > is_attribute(matrix(), "dim") [1] TRUE > is_attribute(matrix(), "class") [1]FME > is_attribute(data.frame(), "class") [1] TRUE > is_attribute{numeric(), "") [1]FME > is_attribute(data.frame()Ir 3) Error in is_attribute(data.frame(), 3) : invalid input for at > is_attribute(list(), C("a", "b")) Error in is_attribute(list(), C("a", "b")) : invalid input for a t > is_attribute(sum, "function"} [1]FME Note: while class is considered an attribute for many object types, such as factors and dataframes, class is not considered an attribute of matrices, lists, or atomic (logical, numeric, and character) vectors. Note that the function c1ass() will still output something for any input object, even NULLStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started