[R] subsetting to exclude different values for each subject in study

Frede Aakmann Tøgersen frtog at vestas.com
Fri May 23 12:58:43 CEST 2014


Hi Monaly

I guess that if you made the neighborhood data available (using dput()) then Arun will easily show you how to automatically with only  a couple of code lines instead of those many lines you had to make by hand.

Have a nice day.

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Monaly Mistry
> Sent: 23. maj 2014 12:34
> To: arun; r-help at r-project.org
> Subject: Re: [R] subsetting to exclude different values for each subject in
> study
>
> Hi,
>
> I did use the library deldir, I didn't put that code in since I  wasn't
> sure if it was really relevant to the question as I just made the
> tesselations identifying which tessellation belonged to which individual.
> Following that I by hand recorded which individuals were sharing a boundary
> with each other.
>
> Best,
>
> Monaly.
>
>
> On Fri, May 23, 2014 at 11:25 AM, arun <smartpink111 at yahoo.com> wrote:
>
> > Hi,
> >
> > I am not sure how you did that.  May be using library(deldir).  I didn't
> > find that codes in your previous email.
> >
> > A.K.
> >
> > On Friday, May 23, 2014 12:42 AM, Monaly Mistry
> <monaly.mistry at gmail.com>
> > wrote:
> >
> >
> >
> > Hi,
> > Neighbours in this case were selected if they shared a boundary in the
> > voroni tesellation.
> >
> > Best,
> > Monaly
> > On May 23, 2014 3:19 AM, "arun" <smartpink111 at yahoo.com> wrote:
> > >
> > >
> > >
> > > HI Monaly,
> > > Thanks for the code and dput.  But, I have a doubt about how you are
> > selecting the neigbours.  Is there another dataset with the information?
> > Sorry, if I have missed something
> > > For e.g.
> > > ### average difference b/n neighbours for each individual
> > > XO["avg", "176"]<- mean(abs((XO[1,"176"])-XO[1,c("140","162","713")]))
> > >
> > >
> > > A.K.
> > >
> > >
> > > On Thursday, May 22, 2014 5:21 PM, Monaly Mistry <
> > monaly.mistry at gmail.com> wrote:
> > > Hi Everyone,
> > >
> > > I hope I did this correctly (I called my data frame ao) and Thank you
> > very
> > > much for the info about using dput(), I'm starting to understand all the
> > > different things that can be done in R and I appreciate all the advice.
> > I
> > > must appologize in advance since my coding is quite long but hopefully it
> > > makes sense. and there is a efficient way to do this.
> > >
> > > structure(list(num = 1:99, FORM_CHK = c(20870L, 22018L, 30737L,
> > > 22010L, 22028L, 36059L, 36063L, 36066L, 30587L, 30612L, 36056L,
> > > 30376L, 35153L, 30435L, 30536L, 30486L, 30475L, 36053L, 36048L,
> > > 36076L, 36045L, 36065L, 35772L, 36949L, 35702L, 36894L, 36080L,
> > > 35542L, 35457L, 35533L, 36042L, 36925L, 36827L, 36008L, 35817L,
> > > 36350L, 35985L, 35973L, 35801L, 36639L, 35810L, 35812L, 35807L,
> > > 36351L, 35967L, 35944L, 37006L, 36345L, 36062L, 36077L, 35802L,
> > > 35984L, 36043L, 35769L, 36360L, 36082L, 36071L, 36354L, 35771L,
> > > 35754L, 36295L, 35746L, 36064L, 35779L, 35751L, 35752L, 35785L,
> > > 35792L, 37011L, 36003L, 36040L, 36831L, 36031L, 36652L, 36992L,
> > > 36965L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> > > NA, NA, NA, NA, NA, NA, NA, NA, NA), RingNummerMan =
> structure(c(1L,
> > > 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
> > > 16L, 17L, 19L, 22L, 23L, 24L, 25L, 26L, 27L, 29L, 30L, 31L, 34L,
> > > 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 46L, 47L, 48L,
> > > 49L, 50L, 51L, 52L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 63L,
> > > 65L, 67L, 69L, 70L, 73L, 74L, 75L, 76L, 78L, 79L, 80L, 81L, 82L,
> > > 83L, 85L, 86L, 87L, 88L, 89L, 93L, 96L, 97L, 18L, 20L, 21L, 28L,
> > > 32L, 33L, 45L, 53L, 62L, 64L, 66L, 68L, 71L, 72L, 77L, 84L, 90L,
> > > 91L, 92L, 94L, 95L, 98L, 99L), .Label = c("AJ...75425", "AL...62371",
> > > "AR...11060", "AR...29297", "AR...29307", "AR...29502", "AR...29504",
> > > "AR...29507", "AR...30039", "AR...30085", "AR...30165", "AR...30491",
> > > "AR...30563", "AR...30616", "AR...30652", "AR...30687", "AR...30701",
> > > "AR...30927", "AR...30959", "AR...30963", "AR...30964", "AR...30965",
> > > "AR...30966", "AR...30985", "AR...30988", "AR...40917", "AR...40996",
> > > "AR...45735", "AR...45904", "AR...45928", "AR...47609", "AR...65387",
> > > "AR...65479", "AR...65550", "AR...65629", "AR...65948", "AR...86074",
> > > "AR...86521", "AR...86527", "AR...90061", "AR...90064", "AR...90067",
> > > "AR...90077", "AR...90081", "AR...90098", "AR...90101", "AR...90106",
> > > "AR...90112", "AR...90133", "AR...90155", "AR...90176", "AR...90178",
> > > "AR...90180", "AR...90187", "AR...90212", "AR...90247", "AR...90252",
> > > "AR...90256", "AR...90258", "AR...90269", "AR...90272", "AR...90275",
> > > "AR...90294", "AR...90298", "AR...90300", "AR...90337", "AR...90338",
> > > "AR...90367", "AR...90397", "AR...90410", "AR...90463", "AR...90520",
> > > "AR...90544", "AR...90556", "AR...90678", "AR...90712", "AR...90737",
> > > "AR...90744", "AR...90829", "AR...90862", "AR...90863", "AR...90873",
> > > "AR...90880", "AR...90892", "AR...90898", "AR...90945", "AR...90951",
> > > "AR...90965", "AR...90970", "AR...90972", "AU...15008", "AU...15009",
> > > "AU...15027", "AU...15032", "AU...15036", "AU...15038", "AU...15046",
> > > "AU...15049", "AU...15505"), class = "factor"), year_score_taken =
> > c(2006L,
> > > 2008L, 2009L, 2008L, 2008L, 2011L, 2011L, 2011L, 2009L, 2009L,
> > > 2011L, 2009L, 2010L, 2009L, 2009L, 2009L, 2009L, 2011L, 2011L,
> > > 2011L, 2011L, 2011L, 2011L, 2012L, 2011L, 2012L, 2011L, 2010L,
> > > 2010L, 2010L, 2011L, 2012L, 2012L, 2011L, 2011L, 2012L, 2011L,
> > > 2011L, 2011L, 2012L, 2011L, 2011L, 2011L, 2012L, 2011L, 2011L,
> > > 2013L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L,
> > > 2012L, 2011L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
> > > 2011L, 2011L, 2011L, 2011L, 2013L, 2011L, 2011L, 2012L, 2011L,
> > > 2012L, 2012L, 2012L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> > > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), COR_LOC =
> > c(15.13404,
> > > 13.88054, 30.0969, 19.09152, 16.88054, 14.15718, 39.15718, 16.15718,
> > > 16.13566, 23.07538, 39.15718, 24.56838, 12.13942, 21.4123, 19.06945,
> > > 12.33264, 32.48872, 30.15718, 37.15718, 37.15718, 49.15718, 22.15718,
> > > 18.50272, 23.69432, 24.9322, 47.29712, 41.15718, 21.47903, 38.6588,
> > > 34.99572, 28.15718, 13.08614, 16.71908, 22.68894, 19.2616, 15.96234,
> > > 22.83964, 13.89992, 14.2616, 18.17118, 24.2616, 22.2616, 13.2616,
> > > 23.96234, 24.89992, 24.05062, 10.20884, 6.96234, 13.15718, 17.15718,
> > > 40.2616, 21.83964, 20.15718, 39.50272, 26.81164, 20.3843, 14.15718,
> > > 7.96234, 19.50272, 40.74384, 5.7675, 42.95482, 29.15718, 18.32188,
> > > 28.74384, 37.74384, 22.32188, 25.32188, 18.20884, 14.68894, 22.15718,
> > > 39.71908, 18.2067, 15.1109, 15.61466, 47.4532, NA, NA, NA, NA,
> > > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> > > NA, NA, NA), IndividuID = c(11394L, 15676L, 342518L, 344902L,
> > > 344909L, 377497L, 377499L, 377504L, 352003L, 351986L, 352260L,
> > > 352392L, 353800L, 353892L, 353949L, 354060L, 354074L, 377487L,
> > > 377490L, 377511L, 377513L, 377495L, 377297L, 357796L, 366326L,
> > > 378446L, 377518L, 358157L, 358730L, 366215L, 377519L, 378407L,
> > > 378453L, 377443L, 377358L, 377726L, 377422L, 377402L, 377341L,
> > > 378354L, 377350L, 377352L, 377347L, 378408L, 377396L, 377374L,
> > > 377774L, 377743L, 377500L, 377510L, 377342L, 377421L, 377786L,
> > > 377294L, 377836L, 378291L, 377508L, 378199L, 377296L, 377280L,
> > > 373000L, 373020L, 377496L, 377306L, 373025L, 377278L, 377310L,
> > > 377317L, 377337L, 377439L, 377450L, 377464L, 377478L, 400290L,
> > > 400361L, 400260L, 357889L, 377477L, 377298L, 400370L, 356930L,
> > > 356939L, 378115L, 377562L, 378018L, 377834L, 378290L, 378228L,
> > > 378268L, 378052L, 378103L, 377332L, 377514L, 400356L, 400357L,
> > > 400372L, 400259L, 400256L, 400354L), BroedJaar = c(2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
> > > 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L), ManipulatieOuders =
> > c(0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> > > 0L, 0L), LegBeginDag = c(11L, 15L, 15L, 13L, 8L, 26L, 15L, 16L,
> > > 1L, 3L, 4L, 9L, 13L, 20L, 11L, 2L, 9L, 13L, 31L, 1L, 12L, 8L,
> > > 13L, 7L, 10L, 11L, 17L, 10L, 11L, 19L, 20L, 13L, 14L, 24L, 17L,
> > > 10L, 8L, 29L, 7L, 26L, 10L, 15L, 2L, 6L, 8L, 13L, 1L, 5L, 12L,
> > > 12L, 15L, 19L, 10L, 1L, 5L, 13L, 6L, 5L, 16L, 2L, 2L, 30L, 10L,
> > > 21L, 8L, 19L, 8L, 27L, 3L, 8L, 14L, 18L, 17L, 7L, 4L, 10L, 13L,
> > > 11L, 31L, 25L, 23L, 7L, 7L, 7L, 8L, 3L, 14L, 14L, 15L, 5L, 10L,
> > > 11L, 18L, 1L, 31L, 3L, 8L, 20L, 14L), LegBeginMaand = c(4L, 4L,
> > > 5L, 4L, 5L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> > > 3L, 4L, 4L, 4L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 4L,
> > > 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 4L,
> > > 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 3L, 4L, 4L, 4L, 4L,
> > > 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 4L,
> > > 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 4L,
> > > 4L), broodinfo = c(55334L, 55325L, 55317L, 55349L, 55366L, 55303L,
> > > 55461L, 55528L, 55296L, 55297L, 55630L, 55567L, 55345L, 55444L,
> > > 55526L, 55571L, 55462L, 55346L, 55576L, 55577L, 55601L, 55300L,
> > > 55607L, 55634L, 55558L, 55633L, 55590L, 55594L, 55537L, 55466L,
> > > 55327L, 55603L, 55600L, 55302L, 55319L, 55609L, 55574L, 55310L,
> > > 55554L, 55582L, 55561L, 55320L, 55555L, 55578L, 55343L, 55331L,
> > > 55314L, 55560L, 55460L, 55551L, 55322L, 55306L, 55348L, 55589L,
> > > 55572L, 55565L, 55595L, 55606L, 55323L, 55635L, 55568L, 55614L,
> > > 55447L, 55312L, 55344L, 55321L, 55569L, 55309L, 55570L, 55562L,
> > > 55550L, 55605L, 55465L, 55445L, 55587L, 55332L, 55629L, 55613L,
> > > 55448L, 55632L, 55636L, 55531L, 55329L, 55597L, 55298L, 55596L,
> > > 55318L, 55608L, 55463L, 55532L, 55557L, 55536L, 55333L, 55533L,
> > > 55538L, 55637L, 55330L, 55326L, 55525L), BroedselID = c(55334L,
> > > 55325L, 55317L, 55349L, 55366L, 55303L, 55461L, 55528L, 55296L,
> > > 55297L, 55630L, 55567L, 55345L, 55444L, 55526L, 55571L, 55462L,
> > > 55346L, 55576L, 55577L, 55601L, 55300L, 55607L, 55634L, 55558L,
> > > 55633L, 55590L, 55594L, 55537L, 55466L, 55327L, 55603L, 55600L,
> > > 55302L, 55319L, 55609L, 55574L, 55310L, 55554L, 55582L, 55561L,
> > > 55320L, 55555L, 55578L, 55343L, 55331L, 55314L, 55560L, 55460L,
> > > 55551L, 55322L, 55306L, 55348L, 55589L, 55572L, 55565L, 55595L,
> > > 55606L, 55323L, 55635L, 55568L, 55614L, 55447L, 55312L, 55344L,
> > > 55321L, 55569L, 55309L, 55570L, 55562L, 55550L, 55605L, 55465L,
> > > 55445L, 55587L, 55332L, 55629L, 55613L, 55448L, 55632L, 55636L,
> > > 55531L, 55329L, 55597L, 55298L, 55596L, 55318L, 55608L, 55463L,
> > > 55532L, 55557L, 55536L, 55333L, 55533L, 55538L, 55637L, 55330L,
> > > 55326L, 55525L), NestkastNummer = c(176L, 124L, 51L, 717L, 54L,
> > > 19L, 11L, 42L, 90L, 9L, 713L, 82L, 709L, 2L, 39L, 86L, 16L, 710L,
> > > 93L, 94L, 163L, 14L, 170L, 718L, 79L, 715L, 130L, 133L, 57L,
> > > 25L, 128L, 164L, 162L, 15L, 60L, 172L, 91L, 31L, 73L, 97L, 111L,
> > > 64L, 74L, 95L, 704L, 148L, 36L, 80L, 8L, 68L, 105L, 22L, 716L,
> > > 127L, 88L, 81L, 140L, 169L, 109L, 719L, 35L, 185L, 6L, 34L, 707L,
> > > 101L, 38L, 28L, 84L, 113L, 62L, 168L, 23L, 3L, 117L, 150L, 705L,
> > > 183L, 7L, 714L, 720L, 49L, 144L, 153L, 12L, 143L, 56L, 171L,
> > > 17L, 50L, 77L, 55L, 175L, 52L, 58L, 722L, 145L, 125L, 32L), lat_xm =
> > > c(729.2669944,
> > > 1001.809576, 501.4865527, 105.2662516, 622.0842564, 313.4718688,
> > > 198.828763, 248.3819471, 466.4434076, 155.709257, 433.2482345,
> > > 388.4860969, 306.5590574, 14.98895776, 191.9843836, 309.4336924,
> > > 308.6123573, 351.526526, 606.8213156, 601.8249333, 912.0799656,
> > > 267.5461811, 1084.557939, 264.26089, 359.6713191, 488.4822672,
> > > 1018.578266, 915.707476, 773.276261, 171.4513083, 1084.831712,
> > > 952.5985963, 878.4741353, 288.3530553, 913.9963847, 1071.827424,
> > > 456.313756, 51.12730755, 582.6607182, 592.1059359, 740.3548678,
> > > 1042.875765, 476.8468377, 654.0474325, 276.375404, 877.6528113,
> > > 135.7921596, 300.9466765, 145.6480126, 829.1262723, 601.4827177,
> > > 237.6363065, 500.3230173, 1129.730741, 398.06821, 340.8493193,
> > > 770.4016222, 1051.63655, 571.7097287, 314.4300781, 117.5861334,
> > > 437.9708453, 95.41039954, 105.7453938, 235.5829892, 627.9704095,
> > > 177.0636713, 99.17481232, 396.6993402, 973.4739067, 1034.662528,
> > > 1046.77705, 221.278275, 27.24031031, 724.0652756, 942.6742674,
> > > 325.9970589, 261.933799, 116.7648206, 464.0478832, 532.6968545,
> > > 423.9399058, 656.8536222, 979.9076146, 221.2098377, 701.5473216,
> > > 709.8290013, 1120.559295, 345.5719307, 463.4318862, 429.6207308,
> > > 659.112262, 717.7684649, 533.3812884, 819.3388243, 600.9351721,
> > > 722.4910753, 1126.719223, 26.8297633), long_ym = c(385.4016022,
> > > 744.3388344, 1278.519267, 582.1054392, 1183.781188, 1313.545671,
> > > 1155.204087, 1008.093201, 812.6125238, 1045.899477, 474.135164,
> > > 887.4467064, 626.9169985, 700.9728169, 849.3068501, 799.1579293,
> > > 1418.180093, 598.1175046, 928.3664402, 1111.83807, 367.2768291,
> > > 1318.32705, 501.4891137, 542.5200518, 1095.7148, 552.6387801,
> > > 636.2573659, 479.9172936, 1057.018971, 980.7392501, 739.0014835,
> > > 485.8106446, 371.9470232, 1365.91848, 942.3769994, 664.2784869,
> > > 887.335514, 669.5046549, 1156.983212, 893.8960158, 933.9261864,
> > > 783.4794517, 1191.342439, 975.8466709, 453.8976828, 55.70866057,
> > > 731.2178331, 973.6227733, 1002.199869, 920.5827929, 678.1778549,
> > > 1141.415921, 578.9919757, 710.2019861, 738.8902861, 936.706063,
> > > 480.8068625, 454.8984371, 771.1368166, 510.940689, 680.7353401,
> > > 1087.041598, 895.6751282, 641.8171157, 573.7658194, 651.9358502,
> > > 816.2819528, 819.6178023, 828.7357905, 801.8266126, 856.9792948,
> > > 415.0906484, 1086.374437, 737.4447458, 559.866446, 0, 423.6526577,
> > > 1166.990753, 957.8330951, 562.8687158, 564.7590286, 1339.676479,
> > > 197.5933584, 132.099559, 1205.686591, 246.6303384, 1106.500715,
> > > 597.3391415, 1389.380609, 1312.878499, 1155.760068, 1152.090634,
> > > 433.6602223, 1252.833235, 1028.88666, 522.3937678, 151.7810272,
> > > 796.3780665, 631.3647851), avg_pop_eb = c(23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359, 23.57103359, 23.57103359, 23.57103359,
> > > 23.57103359, 23.57103359)), .Names = c("num", "FORM_CHK",
> > "RingNummerMan",
> > > "year_score_taken", "COR_LOC", "IndividuID", "BroedJaar",
> > > "ManipulatieOuders",
> > > "LegBeginDag", "LegBeginMaand", "broodinfo", "BroedselID",
> > > "NestkastNummer",
> > > "lat_xm", "long_ym", "avg_pop_eb"), class = "data.frame", row.names =
> > c(NA,
> > > -99L))
> > >
> > >
> > > #Below is the code I made to run my analyses
> > > XO<- matrix( 0,6, 76, byrow=TRUE);XO  #I first made a matrix to store my
> > > results in
> > > names(ao)
> > > ao$NestkastNummer
> > > b<-c(77:99)
> > > abo<-ao$NestkastNummer[-b];abo   #removed values that were NA
> > > rownames(XO) = c("EB_score","avg","pop_size","pop_avg_score",
> > > "adj_pop_avg", "ind_pop_dif")
> > > colnames(XO) = c((abo))
> > > ncol(XO)
> > > names(ao)
> > > t <- ao$COR_LOC;t
> > > i <- c(77:99)
> > > ti <- t[-i];ti
> > > XO[1,] = c(ti);XO  #assigned values from data frame to the matrix
> > >
> > > ### average difference b/n neighbours for each individual
> > > XO["avg", "176"]<- mean(abs((XO[1,"176"])-XO[1,c("140","162","713")]))
> > > XO["avg", "124"]<-
> > > mean(abs((XO[1,"124"])-XO[1,c("113","64","128","172","130","117")]))
> > > XO["avg", "51"]<- mean(abs((XO[1,"51"])-XO[1,c("74")]))
> > > XO["avg", "717"]<-
> > mean(abs((XO[1,"717"])-XO[1,c("34","707","704","718")]))
> > > XO["avg", "54"]<- mean(abs((XO[1,"54"])-XO[1,c("73","94")]))
> > > XO["avg", "19"]<- mean(abs((XO[1,"19"])-XO[1,c("15","14")]))
> > > XO["avg", "11"]<- mean(abs((XO[1,"11"])-XO[1,c("22","23","9")]))
> > > XO["avg", "42"]<-
> > > mean(abs((XO[1,"42"])-XO[1,c("23","79","80","39","25","9")]))
> > > XO["avg", "90"]<-
> > mean(abs((XO[1,"90"])-XO[1,c("91","97","109","88","84")]))
> > > XO["avg", "9"]<- mean(abs((XO[1,"9"])-XO[1,c("11","23","42","25","8")]))
> > > XO["avg", "713"]<-
> > mean(abs((XO[1,"713"])-XO[1,c("715","719","710","176")]))
> > > XO["avg", "82"]<- mean(abs((XO[1,"82"])-XO[1,c("81","91","84","86")]))
> > > XO["avg", "709"]<-
> > > mean(abs((XO[1,"709"])-XO[1,c("36","86","88","710","718","707","35")]))
> > > XO["avg", "2"]<- mean(abs((XO[1,"2"])-XO[1,c("3","31")]))
> > > XO["avg", "39"]<-
> > > mean(abs((XO[1,"39"])-XO[1,c("25","42","80","81","86","38","28","6")]))
> > > XO["avg", "86"]<-
> > > mean(abs((XO[1,"86"])-
> XO[1,c("38","39","81","82","84","88","709","36")]))
> > > XO["avg", "16"]<- mean(abs((XO[1,"16"])-XO[1,c("15")]))
> > > XO["avg", "710"]<-
> > > mean(abs((XO[1,"710"])-XO[1,c("709","88","713","719","718")]))
> > > XO["avg", "93"]<-
> > > mean(abs((XO[1,"93"])-XO[1,c("185","94","95","111","97","91")]))
> > > XO["avg", "94"]<-
> > mean(abs((XO[1,"94"])-XO[1,c("73","54","95","93","185")]))
> > > XO["avg", "163"]<-
> > mean(abs((XO[1,"163"])-XO[1,c("133","164","168","162")]))
> > > XO["avg", "14"]<- mean(abs((XO[1,"14"])-XO[1,c("15","19")]))
> > > XO["avg", "170"]<-
> > mean(abs((XO[1,"170"])-XO[1,c("130","164","169","168")]))
> > > XO["avg", "718"]<-
> > > mean(abs((XO[1,"718"])-XO[1,c("707","709","710","719","704")]))
> > > XO["avg", "79"]<-
> > > mean(abs((XO[1,"79"])-XO[1,c("23","22","185","81","80","42")]))
> > > XO["avg", "715"]<- mean(abs((XO[1,"715"])-XO[1,c("716","713")]))
> > > XO["avg", "130"]<-
> > > mean(abs((XO[1,"130"])-XO[1,c("124","172","170","164","133","117")]))
> > > XO["avg", "133"]<-
> > > mean(abs((XO[1,"133"])-XO[1,c("117","130","164","163","162","140")]))
> > > XO["avg", "57"]<- mean(abs((XO[1,"57"])-XO[1,c("95","111")]))
> > > XO["avg", "25"]<- mean(abs((XO[1,"25"])-
> XO[1,c("8","9","42","80","39")]))
> > > XO["avg", "128"]<-
> > mean(abs((XO[1,"128"])-XO[1,c("124","64","127","172")]))
> > > XO["avg", "164"]<-
> > > mean(abs((XO[1,"164"])-XO[1,c("130","170","169","168","163","133")]))
> > > XO["avg", "162"]<-
> > mean(abs((XO[1,"162"])-XO[1,c("176","140","133","163")]))
> > > XO["avg", "15"]<- mean(abs((XO[1,"15"])-XO[1,c("16","19","14")]))
> > > XO["avg", "60"]<- mean(abs((XO[1,"60"])-XO[1,c("62","68","113")]))
> > > XO["avg", "172"]<-
> > mean(abs((XO[1,"172"])-XO[1,c("124","128","127","130")]))
> > > XO["avg", "91"]<-
> > > mean(abs((XO[1,"91"])-XO[1,c("185","93","97","90","84","82","81")]))
> > > XO["avg", "31"]<- mean(abs((XO[1,"31"])-
> XO[1,c("2","3","36","35","34")]))
> > > XO["avg", "73"]<- mean(abs((XO[1,"73"])-XO[1,c("74","54","94","185")]))
> > > XO["avg", "97"]<-
> > > mean(abs((XO[1,"97"])-XO[1,c("91","93","111","109","90")]))
> > > XO["avg", "111"]<-
> > > mean(abs((XO[1,"111"])-XO[1,c("95","57","68","101","109","97","93")]))
> > > XO["avg", "64"]<- mean(abs((XO[1,"64"])-
> XO[1,c("113","62","128","124")]))
> > > XO["avg", "74"]<- mean(abs((XO[1,"74"])-XO[1,c("51","73","185")]))
> > > XO["avg", "95"]<- mean(abs((XO[1,"95"])-XO[1,c("94","57","111","93")]))
> > > XO["avg", "704"]<-
> > mean(abs((XO[1,"704"])-XO[1,c("719","718","707","717")]))
> > > XO["avg", "148"]<- mean(abs((XO[1,"148"])-XO[1,c("150")]))
> > > XO["avg", "36"]<-
> > > mean(abs((XO[1,"36"])-XO[1,c("28","38","86","709","707","35","3")]))
> > > XO["avg", "80"]<-
> > mean(abs((XO[1,"80"])-XO[1,c("42","79","81","39","25")]))
> > > XO["avg", "8"]<- mean(abs((XO[1,"8"])-XO[1,c("9","25")]))
> > > XO["avg", "68"]<-
> > > mean(abs((XO[1,"68"])-XO[1,c("111","60","113","117","101")]))
> > > XO["avg", "105"]<-
> > mean(abs((XO[1,"105"])-XO[1,c("88","109","101","716")]))
> > > XO["avg", "22"]<- mean(abs((XO[1,"22"])-XO[1,c("11","79","23")]))
> > > XO["avg", "716"]<- mean(abs((XO[1,"716"])-XO[1,c("88","105","715")]))
> > > XO["avg", "127"]<- mean(abs((XO[1,"127"])-XO[1,c("128","172")]))
> > > XO["avg", "88"]<-
> > >
> > mean(abs((XO[1,"88"])-
> XO[1,c("86","84","90","109","105","716","710","709")]))
> > > XO["avg", "81"]<-
> > > mean(abs((XO[1,"81"])-XO[1,c("80","79","185","91","82","86","39")]))
> > > XO["avg", "140"]<-
> > mean(abs((XO[1,"140"])-XO[1,c("117","133","162","176")]))
> > > XO["avg", "169"]<- mean(abs((XO[1,"169"])-XO[1,c("164","170","168")]))
> > > XO["avg", "109"]<-
> > > mean(abs((XO[1,"109"])-XO[1,c("90","97","111","101","105","88")]))
> > > XO["avg", "719"]<-
> > mean(abs((XO[1,"719"])-XO[1,c("718","710","713","704")]))
> > > XO["avg", "35"]<-
> > > mean(abs((XO[1,"35"])-XO[1,c("36","709","707","34","31","3")]))
> > > XO["avg", "185"]<-
> > > mean(abs((XO[1,"185"])-XO[1,c("79","74","73","94","93","91","81")]))
> > > XO["avg", "6"]<- mean(abs((XO[1,"6"])-XO[1,c("39","28","3")]))
> > > XO["avg", "34"]<- mean(abs((XO[1,"34"])-
> XO[1,c("31","35","707","717")]))
> > > XO["avg", "707"]<-
> > > mean(abs((XO[1,"707"])-
> XO[1,c("34","35","36","709","718","717","704")]))
> > > XO["avg", "101"]<-
> > > mean(abs((XO[1,"101"])-XO[1,c("105","109","111","68","113","117")]))
> > > XO["avg", "38"]<- mean(abs((XO[1,"38"])-XO[1,c("39","86","36","28")]))
> > > XO["avg", "28"]<- mean(abs((XO[1,"28"])-
> XO[1,c("6","39","38","36","3")]))
> > > XO["avg", "84"]<-
> > mean(abs((XO[1,"84"])-XO[1,c("82","91","90","88","86")]))
> > > XO["avg", "113"]<-
> > > mean(abs((XO[1,"113"])-XO[1,c("68","60","62","64","124","117","101")]))
> > > XO["avg", "62"]<- mean(abs((XO[1,"62"])-XO[1,c("60","64","113")]))
> > > XO["avg", "168"]<-
> > mean(abs((XO[1,"168"])-XO[1,c("170","169","164","163")]))
> > > XO["avg", "23"]<-
> > mean(abs((XO[1,"23"])-XO[1,c("9","11","22","79","42")]))
> > > XO["avg", "3"]<-
> > mean(abs((XO[1,"3"])-XO[1,c("6","28","36","35","31","2")]))
> > > XO["avg", "117"]<-
> > >
> > mean(abs((XO[1,"117"])-
> XO[1,c("101","113","124","130","133","140","68")]))
> > > XO["avg", "150"]<- mean(abs((XO[1,"150"])-XO[1,c("148")]))
> > > XO["pop_size",] <- 76
> > > XO["pop_avg_score",]<- mean(XO["EB_score",])
> > > for (i in XO){
> > >   XO["adj_pop_avg",] <-
> > >
> > ((XO["pop_avg_score",])*(XO["pop_size",])-
> (XO["EB_score",]))/((XO["pop_size",]-1))
> > >   #here I ran a loop to get info
> > >   XO["ind_pop_dif",] <-abs((XO["EB_score",]-XO["adj_pop_avg",]))}
> > > t.test(XO["avg",], XO["ind_pop_dif",], paired=TRUE)
> > > XO
> > > XO<-rbind(XO,0)
> > > rownames(XO)<-c("EB_score","avg","pop_size","pop_avg_score",
> > "adj_pop_avg",
> > > "ind_pop_dif", "non_nei")
> > > XO["non_nei",]<-0
> > > rowMeans(XO[,1:76])
> > >
> > > #This is the average observed discrepancy from individuals to neighbours
> > > #IOW on average how different is a focal bird in this year different from
> > > its neighbours
> > > obso=mean(XO["avg",])
> > > print(paste("Observed=", obso))
> > > XY[15,1]<-round(obso, digits=4)
> > >
> > >
> > > #This is the code I previously posted to find the difference in scores
> > > between a single subject and its non-neighbours
> > > o<-(ao[,c(13,5)])
> > > o<-na.omit(o)
> > > o<-o[!o$NestkastNummer %in% c(176,140,162,713),]
> > > XO[7,1]<-abs((XO[1,"176"]-(mean(o[,"COR_LOC"]))))
> > >
> > >
> > > Best,
> > >
> > > Monaly.
> > >
> > >
> > > On Thu, May 22, 2014 at 5:08 PM, John Kane <jrkrideau at inbox.com>
> wrote:
> > >
> > > > Re dput() etc
> > > > https://github.com/hadley/devtools/wiki/Reproducibility
> > > >
> > > >
> > http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-
> reproducible-example
> > > >
> > > > What dput() does is take your data and ouput it in an ascii format that
> > > > let's the reader here create an exact duplicate of your database.
> > > >
> > > > R is not WYSIWYG. Often what you see on the screen does not tell the
> > whole
> > > > tale. R supports a number of different data types: vectors, matrices,
> > > > data.frames, lists, arrays and others. This site gives a useful though
> > not
> > > > complete summary of many data types
> > > > http://www.statmethods.net/input/datatypes.html. When you have
> just
> > > > created a new data set, or even when working with one that you have
> not
> > > > worked with in some time it is a good idea to do a str() and class()
> > on the
> > > > data object just to be sure that you are working with the data types
> > you
> > > > think you have. What looks like a column of numbers in a data.frame
> may
> > > > actually be a set of factors or a set of character (text) data and
> > you're
> > > > left wondering why multiplying it by some number is not working.
> > > >
> > > > Here is a short example to illustrate. Just copy and paste in the code
> > > >  dat1  <- data.frame(aa = as.factor(1:5), bb = 1:5)
> > > > dat1 # data looks identical on the screen
> > > > 5*dat1[,"aa"]  # oops
> > > > 5*dat1[, "bb"] # okay
> > > > str(dat1)
> > > >
> > > >
> > > > John Kane
> > > > Kingston ON Canada
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: monaly.mistry at gmail.com
> > > > > Sent: Thu, 22 May 2014 16:31:39 +0100
> > > > > To: smartpink111 at yahoo.com, r-help at r-project.org
> > > > > Subject: Re: [R] subsetting to exclude different values for each
> > subject
> > > > > in study
> > > > >
> > > > > Hi,
> > > > >
> > > > > Sorry I'm fairly new to R and I don't really understand using dput(),
> > > > > when
> > > > > you say reproducible example do you mean the code with the
> output?
> > > > >
> > > > > Best,
> > > > >
> > > > > Monaly.
> > > > >
> > > > >
> > > > > On Thu, May 22, 2014 at 4:03 PM, arun <smartpink111 at yahoo.com>
> > wrote:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> It would be helpful if you provide a reproducible example using
> > ?dput().
> > > > >>
> > > > >> A.K.
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >> On Thursday, May 22, 2014 10:15 AM, Monaly Mistry
> > > > >> <monaly.mistry at gmail.com>
> > > > >> wrote:
> > > > >> Hi,
> > > > >>
> > > > >> I've written a code to determine the difference in score for a
> > single
> > > > >> subject and its non-neighbours
> > > > >>
> > > > >> o<-(ao[,c(13,5)]) ##this is the table with the relevant information
> > > > >> o<-na.omit(o)  ##omitted data with NA
> > > > >> o<-o[!o$NestkastNummer %in% c(176,140,162,713),] ##removed
> > neighbours
> > > > >> XO[7,1]<-abs((XO[1,"176"]-(mean(o[,"COR_LOC"]))))  #difference
> > between
> > > > >> that
> > > > >> individual and average non-neighbours scores
> > > > >>
> > > > >> Since each subject has a different number of non-neighbours I was
> > > > >> wondering
> > > > >> if there is an efficient way of writing the code, instead of
> > writing the
> > > > >> same code again and again (76 subjects) for each subject and its
> > > > >> non-neighbours.
> > > > >>
> > > > >>
> > > > >> Best,
> > > > >>
> > > > >> Monaly.
> > > > >>
> > > > >>     [[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.
> > > > >>
> > > > >>
> > > > >
> > > > >       [[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.
> > > >
> > > >
> __________________________________________________________
> __
> > > > FREE ONLINE PHOTOSHARING - Share your photos online with your
> friends
> > and
> > > > family!
> > > > Visit http://www.inbox.com/photosharing to find out more!
> > > >
> > > >
> > > >
> > >
> > >     [[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.
> >
>
>       [[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.



More information about the R-help mailing list