Looking for help with a very basic R assignment. I'm taking a course for complete novices. I'm not quite sure about how to get R to spit out the mode (#3), I can't find any command for it online or in my textbook.
1. Create a list with four elements - two character, one numeric and one logical
2. Extract the logical element
3. What are the mode and class of the results of #11
This is what I have so far:
x = c('Hello', 'Hi', 400, 5 > 1)
x[4]
mode(x)???
class(x)
Thanks. I know this is super basic stuff, no bully pls.
>>375287
>x = c('Hello', 'Hi', 400, 5 > 1)
This doesn't quite work (if you type mode(x) you'll see that x is a character vector) because the 'c' function will assume you want a character vector and try to coerce the non-character elements into strings. You want
x = list('Hello', 'Hi', 400, 5 > 1)
mode(x)
>x[4]
Since x is a list instead of a vector, you'll need to double up on square brackets to extract elements, i.e.
x[[4]]
(x[4] will return a list containing the single element TRUE, instead of the element itself. To verify this, type "str(x[[4]])" and "str(x[4])" without quotes.)
>mode(x)???
>class(x)
That's correct, unless your assignment is interpreting "mode" in the statistical sense (most common element) instead of the R sense (the type of x, in programming lingo).