Matthew
Matthew

Reputation: 45

Subset function does not have type as argument?

I'm following descriptions from a book and it says that subset has a type argument as shown below. However, R keeps throwing the following error message:

"Error in eval(e, x, parent.frame()) : object 'type' not found"

Someone please help indicate why the error arises with the following code:

spam <- subset(sms_raw, type == "spam")

Factors:

'data.frame':   5572 obs. of  5 variables:
 $ ï..v1: Factor w/ 2 levels "ham","spam": 1 1 2 1 1 2 1 1 2 2 .

Upvotes: 0

Views: 40

Answers (1)

prosoitos
prosoitos

Reputation: 7407

To see what the arguments of subset() are, run:

?subset

You will then see that one of its arguments is called subset and is a

logical expression indicating elements or rows to keep

This is what you want (you want to subset rows which test positive for type == "spam").

If your data frame had a variable called type, then your code would work. So rename the variable containing the values "ham" and "spam" to type or replace type by the name of that variable in your code.

Upvotes: 1

Related Questions