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?
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.
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.
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’.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With