[R] subsetting to exclude different values for each subject in study
arun
smartpink111 at yahoo.com
Sat May 24 03:41:26 CEST 2014
Hi,
Sorry, there is a mistake. XO[2,] should be:
XO[2,] <- sapply(seq_along(col.tri.nb), function(i){ind1 <- as.character(ind[i]); ind2 <- as.character(ind[col.tri.nb[[i]]]); mean(abs(XO[1,ind1]-XO[1,ind2]))} )
A.K.
On Friday, May 23, 2014 12:56 PM, arun <smartpink111 at yahoo.com> wrote:
Hi Monaly,
May be this helps:
b<- 77:99
ao1 <- ao[-b,]
##Your code:
XO<- matrix( 0,6, 76, byrow=TRUE);XO
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) = abo
t <- ao$COR_LOC;t
i <- c(77:99)
ti <- t[-i];ti
XO[1,] = c(ti);XO
library(deldir)
library(spdep)
mat <- cbind(lat=ao1$lat_xm, long=ao1$long_ym)
library(spdep)
coords <- coordinates(mat)
ind <- ao1$NestkastNummer
col.tri.nb <- tri2nb(coords, row.names=ind)
lapply(col.tri.nb,function(x) ind[x])[1:5] ###
[[1]]
[1] 713 715 162 148 140 117
[[2]]
[1] 130 128 172 64 113 117
[[3]]
[1] 54 19 16 73 74
[[4]]
[1] 2 31 704 34 707
[[5]]
[1] 51 94 57 73 62
XO[2,] <- sapply(seq_along(col.tri.nb),function(i) mean(abs(ind[i]-ind[col.tri.nb[[i]]])))
A.K.
On Friday, May 23, 2014 7:17 AM, Monaly Mistry <monaly.mistry at gmail.com> wrote:
Hi Arun and Frede,
So the dput() is below (it's the same data file as before), but below that is the code I used to make the tessellation. Thanks for your help.
> dput(ao)
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))
#Code for tessellation
library(deldir)
ao= read.table("C:/Users/Monaly/Desktop/2012_malenest.txt", header=TRUE)
a29= deldir(ao$lat_xm, ao$long_ym)
a30=tile.list(a29)
plot(a30, close=TRUE, main="2012 Male Nest", xlab="latitude (m)", ylab="longitude (m)", wpoints="real", verbose=FALSE,num=TRUE, rw=c(0, 1200, 0, 2000))
text(ao$lat_xm, ao$long_ym,col=c(2,1,4),labels=round(ao$NestkastNummer, 3), pos=2, offset=0.2, cex=0.7) #this was to identify the points
More information about the R-help
mailing list