Re: [R] selecting every nth item in the data

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Tue 25 Oct 2005 - 14:45:59 EST

On 25 Oct 2005 at 13:48, Stephen Choularton wrote:

From:           	"Stephen Choularton" <mail@bymouth.com>
To:             	"R Help" <r-help@stat.math.ethz.ch>
Date sent:      	Tue, 25 Oct 2005 13:48:42 +1000
Subject:        	[R] selecting every nth item in the data

> I want to make a glm and then use predict. I have a fairly small
> sample (4000 cases) and I want to train on 90% and test on 10% but I
> want to do it in slices so I test on every 10th case and train on the
> others. Is there some simple way to get these elements?

As glm accept subet you probably can use

test<-seq(1,4000,n)

glm(...., subset = test)

to select only n'th item or

glm(...., subset = -test)

to select all but n'th items.

or you can split the data freme by

mydf[test,] or mydf[-test,]

HTH
Petr

>
> Stephen
>
> --
>
>
>
> 21/10/2005
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Oct 25 14:50:37 2005

This archive was generated by hypermail 2.1.8 : Tue 25 Oct 2005 - 15:12:27 EST