Using a subset argument with the R t.test command

I would like to select everything except row 646 of the data frame using the argument of a subset of the R 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 did not work. Any suggestions?

+4
source share
1 answer

You just need to specify the vector from which to remove, for example:

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 information about the argument subset=is available at ?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’.
+5
source

Source: https://habr.com/ru/post/1542412/


All Articles