[R] Want to exclude a column when using sample function

Joshua Wiley jwiley.psych at gmail.com
Wed Jul 14 19:28:15 CEST 2010


On Wed, Jul 14, 2010 at 10:24 AM, Federico Andreis
<federico.andreis at gmail.com> wrote:
> I guess you could just use as an argument to sample
>
> data[,-c(1,2)]
>
> where 1 and 2 are id and pID50 column number

or if you do not know them and do not want to find out:

sample(data[ , - match(c("id", "x3"), names(data))], 3, replace=FALSE)


>
> On Wed, Jul 14, 2010 at 7:17 PM, Addi Wei <addiwei at gmail.com> wrote:
>
>>
>>      id pID50      apol     a_acc    a_acid     a_aro a_base   a_count
>> 1 mol.11  3.63 -0.882267 -0.527967 -0.298197 -1.032380      0 -1.063410
>> 2 mol.14  3.38 -1.007330 -0.527967 -0.298197 -1.032380      0 -1.063410
>> 3 mol.19  3.18  1.153560  1.407910 -0.298197  1.254100      0  1.160080
>> 4 mol.20  3.14  0.183448 -0.527967 -0.298197  0.873019      0  0.290021
>> 5 mol.29  2.77 -0.273901 -0.527967 -0.298197  0.110860      0 -0.193347
>> 6 mol.30  2.74 -0.230593 -0.527967 -0.298197  0.110860      0  0.000000
>> 7 mol.40  2.16 -1.117550 -0.527967 -0.298197 -1.032380      0 -1.256760
>> 8 mol.45  1.90 -0.383560 -0.527967 -0.298197  0.110860      0 -0.290021
>> 9 mol.48  1.73 -0.383560 -0.527967 -0.298197  0.110860      0 -0.290021
>>
>>
>> What if I want to exclude 2 columns?
>> For example:   sample(data, 3, replace=FALSE)     ##from my sample, i want
>> to exclude both id and pID50
>>
>> Thanks much.
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Want-to-exclude-a-column-when-using-sample-function-tp2287988p2289092.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list