Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the subset argument with R's t.test command

Tags:

r

I'd like to select all but the 646 row of a data frame by using the subset argument of R's t.test command. I tried:

require(mosaic)
require(Sleuth3)

t.test(Dioxin~Veteran,data=case0302,var.equal=TRUE,alternative="less",
       subset=case0302[-646,])

But that didn't work. Any suggestions?

like image 610
David Avatar asked May 29 '14 01:05

David


People also ask

What is the use of subset () function and sample () function in R?

The difference between subset () function and sample () is that, subset () is used to select data from the dataset which meets certain condition, while sample () is used for randomly selecting data of size 'n' from the dataset.

What is subset command in R?

Subsetting in R is a useful indexing feature for accessing object elements. It can be used to select and filter variables and observations. You can use brackets to select rows and columns from your dataframe.


1 Answers

You just need to specify a vector of which cases to drop, like:

test <- data.frame(x=rnorm(100),y=rep(1:2,each=50))
t.test(x ~ y, data=test, subset=-40)

So in your case it should be:

t.test(Dioxin~Veteran,data=case0302,var.equal=TRUE,alternative="less",
   subset=-646)

As @flodel notes, more info on the subset= argument is available in ?model.frame:

  subset: a specification of the rows to be used: defaults to all rows.
          This can be any valid indexing vector (see ‘[.data.frame’)
          for the rows of ‘data’ or if that is not supplied, a data
          frame made up of the variables used in ‘formula’.
like image 128
thelatemail Avatar answered Oct 15 '22 13:10

thelatemail