I have a list of numbers with NAs as below:> A[,1][1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [19] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [37] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [55] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [73] NA NA NA 62 78 98 73 57 63 56 88 77 151 165 129 78 83 63 [91] 72 68 61 89 95 74 53 77 90 106 114 113 84 59 60 77 46 91 [109] 108 111 76 75 70 61 65 61 52 94 71 67 52 86 79 97 80 101 [127] 87 53 85 79 86 104 153 128 155 148 NA NA NA NA NA NA NA NA [145] NA NA NA NA NA NA NA I would like to bind a column to this list which begins at 0 when the first number has occured, but provides negative numbers prior to this as below: [1,] -75 NA [2,] -74 NA [3,] -73 NA [4,] -72 NA [5,] -71 NA [6,] -70 NA [7,] -69 NA [8,] -68 NA [9,] -67 NA [10,] -66 NA [11,] -65 NA [12,] -64 NA [13,] -63 NA [14,] -62 NA [15,] -61 NA [16,] -60 NA [17,] -59 NA [18,] -58 NA [19,] -57 NA [20,] -56 NA [21,] -55 NA [22,] -54 NA [23,] -53 NA [24,] -52 NA [25,] -51 NA [26,] -50 NA [27,] -49 NA [28,] -48 NA [29,] -47 NA [30,] -46 NA [31,] -45 NA [32,] -44 NA [33,] -43 NA [34,] -42 NA [35,] -41 NA [36,] -40 NA [37,] -39 NA [38,] -38 NA [39,] -37 NA [40,] -36 NA [41,] -35 NA [42,] -34 NA [43,] -33 NA [44,] -32 NA [45,] -31 NA [46,] -30 NA [47,] -29 NA [48,] -28 NA [49,] -27 NA [50,] -26 NA [51,] -25 NA [52,] -24 NA [53,] -23 NA [54,] -22 NA [55,] -21 NA [56,] -20 NA [57,] -19 NA [58,] -18 NA [59,] -17 NA [60,] -16 NA [61,] -15 NA [62,] -14 NA [63,] -13 NA [64,] -12 NA [65,] -11 NA [66,] -10 NA [67,] -9 NA [68,] -8 NA [69,] -7 NA [70,] -6 NA [71,] -5 NA [72,] -4 NA [73,] -3 NA [74,] -2 NA [75,] -1 NA [76,] 0 62 [77,] 1 78 [78,] 2 98 [79,] 3 73 [80,] 4 57 [81,] 5 63 [82,] 6 56 [83,] 7 88 [84,] 8 77 [85,] 9 151 [86,] 10 165 [87,] 11 129 [88,] 12 78 [89,] 13 83 [90,] 14 63 [91,] 15 72 [92,] 16 68 [93,] 17 61 [94,] 18 89 [95,] 19 95 [96,] 20 74 [97,] 21 53 [98,] 22 77 [99,] 23 90 [100,] 24 106 [101,] 25 114 [102,] 26 113 [103,] 27 84 [104,] 28 59 [105,] 29 60 [106,] 30 77 [107,] 31 46 [108,] 32 91 [109,] 33 108 [110,] 34 111 [111,] 35 76 [112,] 36 75 [113,] 37 70 [114,] 38 61 [115,] 39 65 [116,] 40 61 [117,] 41 52 [118,] 42 94 [119,] 43 71 [120,] 44 67 [121,] 45 52 [122,] 46 86 [123,] 47 79 [124,] 48 97 [125,] 49 80 [126,] 50 101 [127,] 51 87 [128,] 52 53 [129,] 53 85 [130,] 54 79 [131,] 55 86 [132,] 56 104 [133,] 57 153 [134,] 58 128 [135,] 59 155 [136,] 60 148 [137,] 61 NA [138,] 62 NA [139,] 63 NA [140,] 64 NA [141,] 65 NA [142,] 66 NA [143,] 67 NA [144,] 68 NA [145,] 69 NA [146,] 70 NA [147,] 71 NA [148,] 72 NA [149,] 73 NA [150,] 74 NA [151,] 75 NA could anyone help me to with a function that would be able to calculate the sequence I require to bind to the initial sequence? thanks emma -- View this message in context: http://www.nabble.com/cbind-tp23036759p23036759.html Sent from the R help mailing list archive at Nabble.com.
try this: x <- c(rep(NA, 20), sample(100, 25)) n.na <- sum(is.na(x)) cbind(seq(-n.na, length(x) - n.na - 1), x) I hope it helps. Best, Dimitris emj83 wrote:> I have a list of numbers with NAs as below: > >> A[,1] > [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA > NA > [19] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA > NA > [37] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA > NA > [55] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA > NA > [73] NA NA NA 62 78 98 73 57 63 56 88 77 151 165 129 78 83 > 63 > [91] 72 68 61 89 95 74 53 77 90 106 114 113 84 59 60 77 46 > 91 > [109] 108 111 76 75 70 61 65 61 52 94 71 67 52 86 79 97 80 > 101 > [127] 87 53 85 79 86 104 153 128 155 148 NA NA NA NA NA NA NA > NA > [145] NA NA NA NA NA NA NA > > I would like to bind a column to this list which begins at 0 when the first > number has occured, but provides negative numbers prior to this as below: > > [1,] -75 NA > [2,] -74 NA > [3,] -73 NA > [4,] -72 NA > [5,] -71 NA > [6,] -70 NA > [7,] -69 NA > [8,] -68 NA > [9,] -67 NA > [10,] -66 NA > [11,] -65 NA > [12,] -64 NA > [13,] -63 NA > [14,] -62 NA > [15,] -61 NA > [16,] -60 NA > [17,] -59 NA > [18,] -58 NA > [19,] -57 NA > [20,] -56 NA > [21,] -55 NA > [22,] -54 NA > [23,] -53 NA > [24,] -52 NA > [25,] -51 NA > [26,] -50 NA > [27,] -49 NA > [28,] -48 NA > [29,] -47 NA > [30,] -46 NA > [31,] -45 NA > [32,] -44 NA > [33,] -43 NA > [34,] -42 NA > [35,] -41 NA > [36,] -40 NA > [37,] -39 NA > [38,] -38 NA > [39,] -37 NA > [40,] -36 NA > [41,] -35 NA > [42,] -34 NA > [43,] -33 NA > [44,] -32 NA > [45,] -31 NA > [46,] -30 NA > [47,] -29 NA > [48,] -28 NA > [49,] -27 NA > [50,] -26 NA > [51,] -25 NA > [52,] -24 NA > [53,] -23 NA > [54,] -22 NA > [55,] -21 NA > [56,] -20 NA > [57,] -19 NA > [58,] -18 NA > [59,] -17 NA > [60,] -16 NA > [61,] -15 NA > [62,] -14 NA > [63,] -13 NA > [64,] -12 NA > [65,] -11 NA > [66,] -10 NA > [67,] -9 NA > [68,] -8 NA > [69,] -7 NA > [70,] -6 NA > [71,] -5 NA > [72,] -4 NA > [73,] -3 NA > [74,] -2 NA > [75,] -1 NA > [76,] 0 62 > [77,] 1 78 > [78,] 2 98 > [79,] 3 73 > [80,] 4 57 > [81,] 5 63 > [82,] 6 56 > [83,] 7 88 > [84,] 8 77 > [85,] 9 151 > [86,] 10 165 > [87,] 11 129 > [88,] 12 78 > [89,] 13 83 > [90,] 14 63 > [91,] 15 72 > [92,] 16 68 > [93,] 17 61 > [94,] 18 89 > [95,] 19 95 > [96,] 20 74 > [97,] 21 53 > [98,] 22 77 > [99,] 23 90 > [100,] 24 106 > [101,] 25 114 > [102,] 26 113 > [103,] 27 84 > [104,] 28 59 > [105,] 29 60 > [106,] 30 77 > [107,] 31 46 > [108,] 32 91 > [109,] 33 108 > [110,] 34 111 > [111,] 35 76 > [112,] 36 75 > [113,] 37 70 > [114,] 38 61 > [115,] 39 65 > [116,] 40 61 > [117,] 41 52 > [118,] 42 94 > [119,] 43 71 > [120,] 44 67 > [121,] 45 52 > [122,] 46 86 > [123,] 47 79 > [124,] 48 97 > [125,] 49 80 > [126,] 50 101 > [127,] 51 87 > [128,] 52 53 > [129,] 53 85 > [130,] 54 79 > [131,] 55 86 > [132,] 56 104 > [133,] 57 153 > [134,] 58 128 > [135,] 59 155 > [136,] 60 148 > [137,] 61 NA > [138,] 62 NA > [139,] 63 NA > [140,] 64 NA > [141,] 65 NA > [142,] 66 NA > [143,] 67 NA > [144,] 68 NA > [145,] 69 NA > [146,] 70 NA > [147,] 71 NA > [148,] 72 NA > [149,] 73 NA > [150,] 74 NA > [151,] 75 NA > > could anyone help me to with a function that would be able to calculate the > sequence I require to bind to the initial sequence? > > thanks emma-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
> a=c(NA,NA,2,3,NA,NA,NA) > which.min(is.na(a))[1] 3> b=1:length(a) > b-3[1] -2 -1 0 1 2 3 4> cbind(b=b-3,a=a)b a [1,] -2 NA [2,] -1 NA [3,] 0 2 [4,] 1 3 [5,] 2 NA [6,] 3 NA [7,] 4 NA On Tue, Apr 14, 2009 at 7:20 AM, emj83 <stp08emj at shef.ac.uk> wrote:> > I have a list of numbers with NAs as below: > >> A[,1] > ?[1] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA > NA > ?[19] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA > NA > ?[37] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA > NA > ?[55] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA > NA > ?[73] ?NA ?NA ?NA ?62 ?78 ?98 ?73 ?57 ?63 ?56 ?88 ?77 151 165 129 ?78 ?83 > 63 > ?[91] ?72 ?68 ?61 ?89 ?95 ?74 ?53 ?77 ?90 106 114 113 ?84 ?59 ?60 ?77 ?46 > 91 > [109] 108 111 ?76 ?75 ?70 ?61 ?65 ?61 ?52 ?94 ?71 ?67 ?52 ?86 ?79 ?97 ?80 > 101 > [127] ?87 ?53 ?85 ?79 ?86 104 153 128 155 148 ?NA ?NA ?NA ?NA ?NA ?NA ?NA > NA > [145] ?NA ?NA ?NA ?NA ?NA ?NA ?NA > > I would like to ?bind a column to this list which begins at 0 when the first > number has occured, but provides negative numbers prior to this as below: > > ?[1,] -75 ?NA > ?[2,] -74 ?NA > ?[3,] -73 ?NA > ?[4,] -72 ?NA > ?[5,] -71 ?NA > ?[6,] -70 ?NA > ?[7,] -69 ?NA > ?[8,] -68 ?NA > ?[9,] -67 ?NA > ?[10,] -66 ?NA > ?[11,] -65 ?NA > ?[12,] -64 ?NA > ?[13,] -63 ?NA > ?[14,] -62 ?NA > ?[15,] -61 ?NA > ?[16,] -60 ?NA > ?[17,] -59 ?NA > ?[18,] -58 ?NA > ?[19,] -57 ?NA > ?[20,] -56 ?NA > ?[21,] -55 ?NA > ?[22,] -54 ?NA > ?[23,] -53 ?NA > ?[24,] -52 ?NA > ?[25,] -51 ?NA > ?[26,] -50 ?NA > ?[27,] -49 ?NA > ?[28,] -48 ?NA > ?[29,] -47 ?NA > ?[30,] -46 ?NA > ?[31,] -45 ?NA > ?[32,] -44 ?NA > ?[33,] -43 ?NA > ?[34,] -42 ?NA > ?[35,] -41 ?NA > ?[36,] -40 ?NA > ?[37,] -39 ?NA > ?[38,] -38 ?NA > ?[39,] -37 ?NA > ?[40,] -36 ?NA > ?[41,] -35 ?NA > ?[42,] -34 ?NA > ?[43,] -33 ?NA > ?[44,] -32 ?NA > ?[45,] -31 ?NA > ?[46,] -30 ?NA > ?[47,] -29 ?NA > ?[48,] -28 ?NA > ?[49,] -27 ?NA > ?[50,] -26 ?NA > ?[51,] -25 ?NA > ?[52,] -24 ?NA > ?[53,] -23 ?NA > ?[54,] -22 ?NA > ?[55,] -21 ?NA > ?[56,] -20 ?NA > ?[57,] -19 ?NA > ?[58,] -18 ?NA > ?[59,] -17 ?NA > ?[60,] -16 ?NA > ?[61,] -15 ?NA > ?[62,] -14 ?NA > ?[63,] -13 ?NA > ?[64,] -12 ?NA > ?[65,] -11 ?NA > ?[66,] -10 ?NA > ?[67,] ?-9 ?NA > ?[68,] ?-8 ?NA > ?[69,] ?-7 ?NA > ?[70,] ?-6 ?NA > ?[71,] ?-5 ?NA > ?[72,] ?-4 ?NA > ?[73,] ?-3 ?NA > ?[74,] ?-2 ?NA > ?[75,] ?-1 ?NA > ?[76,] ? 0 ?62 > ?[77,] ? 1 ?78 > ?[78,] ? 2 ?98 > ?[79,] ? 3 ?73 > ?[80,] ? 4 ?57 > ?[81,] ? 5 ?63 > ?[82,] ? 6 ?56 > ?[83,] ? 7 ?88 > ?[84,] ? 8 ?77 > ?[85,] ? 9 151 > ?[86,] ?10 165 > ?[87,] ?11 129 > ?[88,] ?12 ?78 > ?[89,] ?13 ?83 > ?[90,] ?14 ?63 > ?[91,] ?15 ?72 > ?[92,] ?16 ?68 > ?[93,] ?17 ?61 > ?[94,] ?18 ?89 > ?[95,] ?19 ?95 > ?[96,] ?20 ?74 > ?[97,] ?21 ?53 > ?[98,] ?22 ?77 > ?[99,] ?23 ?90 > [100,] ?24 106 > [101,] ?25 114 > [102,] ?26 113 > [103,] ?27 ?84 > [104,] ?28 ?59 > [105,] ?29 ?60 > [106,] ?30 ?77 > [107,] ?31 ?46 > [108,] ?32 ?91 > [109,] ?33 108 > [110,] ?34 111 > [111,] ?35 ?76 > [112,] ?36 ?75 > [113,] ?37 ?70 > [114,] ?38 ?61 > [115,] ?39 ?65 > [116,] ?40 ?61 > [117,] ?41 ?52 > [118,] ?42 ?94 > [119,] ?43 ?71 > [120,] ?44 ?67 > [121,] ?45 ?52 > [122,] ?46 ?86 > [123,] ?47 ?79 > [124,] ?48 ?97 > [125,] ?49 ?80 > [126,] ?50 101 > [127,] ?51 ?87 > [128,] ?52 ?53 > [129,] ?53 ?85 > [130,] ?54 ?79 > [131,] ?55 ?86 > [132,] ?56 104 > [133,] ?57 153 > [134,] ?58 128 > [135,] ?59 155 > [136,] ?60 148 > [137,] ?61 ?NA > [138,] ?62 ?NA > [139,] ?63 ?NA > [140,] ?64 ?NA > [141,] ?65 ?NA > [142,] ?66 ?NA > [143,] ?67 ?NA > [144,] ?68 ?NA > [145,] ?69 ?NA > [146,] ?70 ?NA > [147,] ?71 ?NA > [148,] ?72 ?NA > [149,] ?73 ?NA > [150,] ?74 ?NA > [151,] ?75 ?NA > > could anyone help me to with a function that would be able to calculate the > sequence I require to bind to the initial sequence? > > thanks emma > -- > View this message in context: http://www.nabble.com/cbind-tp23036759p23036759.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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~
oops, of course I meant: a=c(NA,NA,2,3,NA,NA,NA) b=1:length(a) cbind(b=b-which.min(is.na(a)),a=a) On Tue, Apr 14, 2009 at 9:43 AM, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:>> a=c(NA,NA,2,3,NA,NA,NA) >> which.min(is.na(a)) > [1] 3 >> b=1:length(a) >> b-3 > [1] -2 -1 ?0 ?1 ?2 ?3 ?4 >> cbind(b=b-3,a=a) > ? ? ? b ?a > [1,] -2 NA > [2,] -1 NA > [3,] ?0 ?2 > [4,] ?1 ?3 > [5,] ?2 NA > [6,] ?3 NA > [7,] ?4 NA > > > > On Tue, Apr 14, 2009 at 7:20 AM, emj83 <stp08emj at shef.ac.uk> wrote: >> >> I have a list of numbers with NAs as below: >> >>> A[,1] >> ?[1] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> NA >> ?[19] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> NA >> ?[37] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> NA >> ?[55] ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> NA >> ?[73] ?NA ?NA ?NA ?62 ?78 ?98 ?73 ?57 ?63 ?56 ?88 ?77 151 165 129 ?78 ?83 >> 63 >> ?[91] ?72 ?68 ?61 ?89 ?95 ?74 ?53 ?77 ?90 106 114 113 ?84 ?59 ?60 ?77 ?46 >> 91 >> [109] 108 111 ?76 ?75 ?70 ?61 ?65 ?61 ?52 ?94 ?71 ?67 ?52 ?86 ?79 ?97 ?80 >> 101 >> [127] ?87 ?53 ?85 ?79 ?86 104 153 128 155 148 ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> NA >> [145] ?NA ?NA ?NA ?NA ?NA ?NA ?NA >> >> I would like to ?bind a column to this list which begins at 0 when the first >> number has occured, but provides negative numbers prior to this as below: >> >> ?[1,] -75 ?NA >> ?[2,] -74 ?NA >> ?[3,] -73 ?NA >> ?[4,] -72 ?NA >> ?[5,] -71 ?NA >> ?[6,] -70 ?NA >> ?[7,] -69 ?NA >> ?[8,] -68 ?NA >> ?[9,] -67 ?NA >> ?[10,] -66 ?NA >> ?[11,] -65 ?NA >> ?[12,] -64 ?NA >> ?[13,] -63 ?NA >> ?[14,] -62 ?NA >> ?[15,] -61 ?NA >> ?[16,] -60 ?NA >> ?[17,] -59 ?NA >> ?[18,] -58 ?NA >> ?[19,] -57 ?NA >> ?[20,] -56 ?NA >> ?[21,] -55 ?NA >> ?[22,] -54 ?NA >> ?[23,] -53 ?NA >> ?[24,] -52 ?NA >> ?[25,] -51 ?NA >> ?[26,] -50 ?NA >> ?[27,] -49 ?NA >> ?[28,] -48 ?NA >> ?[29,] -47 ?NA >> ?[30,] -46 ?NA >> ?[31,] -45 ?NA >> ?[32,] -44 ?NA >> ?[33,] -43 ?NA >> ?[34,] -42 ?NA >> ?[35,] -41 ?NA >> ?[36,] -40 ?NA >> ?[37,] -39 ?NA >> ?[38,] -38 ?NA >> ?[39,] -37 ?NA >> ?[40,] -36 ?NA >> ?[41,] -35 ?NA >> ?[42,] -34 ?NA >> ?[43,] -33 ?NA >> ?[44,] -32 ?NA >> ?[45,] -31 ?NA >> ?[46,] -30 ?NA >> ?[47,] -29 ?NA >> ?[48,] -28 ?NA >> ?[49,] -27 ?NA >> ?[50,] -26 ?NA >> ?[51,] -25 ?NA >> ?[52,] -24 ?NA >> ?[53,] -23 ?NA >> ?[54,] -22 ?NA >> ?[55,] -21 ?NA >> ?[56,] -20 ?NA >> ?[57,] -19 ?NA >> ?[58,] -18 ?NA >> ?[59,] -17 ?NA >> ?[60,] -16 ?NA >> ?[61,] -15 ?NA >> ?[62,] -14 ?NA >> ?[63,] -13 ?NA >> ?[64,] -12 ?NA >> ?[65,] -11 ?NA >> ?[66,] -10 ?NA >> ?[67,] ?-9 ?NA >> ?[68,] ?-8 ?NA >> ?[69,] ?-7 ?NA >> ?[70,] ?-6 ?NA >> ?[71,] ?-5 ?NA >> ?[72,] ?-4 ?NA >> ?[73,] ?-3 ?NA >> ?[74,] ?-2 ?NA >> ?[75,] ?-1 ?NA >> ?[76,] ? 0 ?62 >> ?[77,] ? 1 ?78 >> ?[78,] ? 2 ?98 >> ?[79,] ? 3 ?73 >> ?[80,] ? 4 ?57 >> ?[81,] ? 5 ?63 >> ?[82,] ? 6 ?56 >> ?[83,] ? 7 ?88 >> ?[84,] ? 8 ?77 >> ?[85,] ? 9 151 >> ?[86,] ?10 165 >> ?[87,] ?11 129 >> ?[88,] ?12 ?78 >> ?[89,] ?13 ?83 >> ?[90,] ?14 ?63 >> ?[91,] ?15 ?72 >> ?[92,] ?16 ?68 >> ?[93,] ?17 ?61 >> ?[94,] ?18 ?89 >> ?[95,] ?19 ?95 >> ?[96,] ?20 ?74 >> ?[97,] ?21 ?53 >> ?[98,] ?22 ?77 >> ?[99,] ?23 ?90 >> [100,] ?24 106 >> [101,] ?25 114 >> [102,] ?26 113 >> [103,] ?27 ?84 >> [104,] ?28 ?59 >> [105,] ?29 ?60 >> [106,] ?30 ?77 >> [107,] ?31 ?46 >> [108,] ?32 ?91 >> [109,] ?33 108 >> [110,] ?34 111 >> [111,] ?35 ?76 >> [112,] ?36 ?75 >> [113,] ?37 ?70 >> [114,] ?38 ?61 >> [115,] ?39 ?65 >> [116,] ?40 ?61 >> [117,] ?41 ?52 >> [118,] ?42 ?94 >> [119,] ?43 ?71 >> [120,] ?44 ?67 >> [121,] ?45 ?52 >> [122,] ?46 ?86 >> [123,] ?47 ?79 >> [124,] ?48 ?97 >> [125,] ?49 ?80 >> [126,] ?50 101 >> [127,] ?51 ?87 >> [128,] ?52 ?53 >> [129,] ?53 ?85 >> [130,] ?54 ?79 >> [131,] ?55 ?86 >> [132,] ?56 104 >> [133,] ?57 153 >> [134,] ?58 128 >> [135,] ?59 155 >> [136,] ?60 148 >> [137,] ?61 ?NA >> [138,] ?62 ?NA >> [139,] ?63 ?NA >> [140,] ?64 ?NA >> [141,] ?65 ?NA >> [142,] ?66 ?NA >> [143,] ?67 ?NA >> [144,] ?68 ?NA >> [145,] ?69 ?NA >> [146,] ?70 ?NA >> [147,] ?71 ?NA >> [148,] ?72 ?NA >> [149,] ?73 ?NA >> [150,] ?74 ?NA >> [151,] ?75 ?NA >> >> could anyone help me to with a function that would be able to calculate the >> sequence I require to bind to the initial sequence? >> >> thanks emma >> -- >> View this message in context: http://www.nabble.com/cbind-tp23036759p23036759.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. >> > > > > -- > Mike Lawrence > Graduate Student > Department of Psychology > Dalhousie University > > Looking to arrange a meeting? Check my public calendar: > http://tr.im/mikes_public_calendar > > ~ Certainty is folly... I think. ~ >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~
Hi Emma, Here's what I suggest: na.vec = is.na(A[,1]) ; first.num.pos = min(which(na.vec==FALSE)) ; first.part = (-first.num.pos+1):(-1) ; second.part = 0:(length(A[,1])-length(first.part)-1) ; Result.mat = cbind(c(first.part,second.part),A[,1]) ; I hope this is what you want. HTH, Luc emj83 wrote: I have a list of numbers with NAs as below: A[,1] [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [19] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [37] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [55] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [73] NA NA NA 62 78 98 73 57 63 56 88 77 151 165 129 78 83 63 [91] 72 68 61 89 95 74 53 77 90 106 114 113 84 59 60 77 46 91 [109] 108 111 76 75 70 61 65 61 52 94 71 67 52 86 79 97 80 101 [127] 87 53 85 79 86 104 153 128 155 148 NA NA NA NA NA NA NA NA [145] NA NA NA NA NA NA NA I would like to bind a column to this list which begins at 0 when the first number has occured, but provides negative numbers prior to this as below: [1,] -75 NA [2,] -74 NA [3,] -73 NA [4,] -72 NA [5,] -71 NA [6,] -70 NA [7,] -69 NA [8,] -68 NA [9,] -67 NA [10,] -66 NA [11,] -65 NA [12,] -64 NA [13,] -63 NA [14,] -62 NA [15,] -61 NA [16,] -60 NA [17,] -59 NA [18,] -58 NA [19,] -57 NA [20,] -56 NA [21,] -55 NA [22,] -54 NA [23,] -53 NA [24,] -52 NA [25,] -51 NA [26,] -50 NA [27,] -49 NA [28,] -48 NA [29,] -47 NA [30,] -46 NA [31,] -45 NA [32,] -44 NA [33,] -43 NA [34,] -42 NA [35,] -41 NA [36,] -40 NA [37,] -39 NA [38,] -38 NA [39,] -37 NA [40,] -36 NA [41,] -35 NA [42,] -34 NA [43,] -33 NA [44,] -32 NA [45,] -31 NA [46,] -30 NA [47,] -29 NA [48,] -28 NA [49,] -27 NA [50,] -26 NA [51,] -25 NA [52,] -24 NA [53,] -23 NA [54,] -22 NA [55,] -21 NA [56,] -20 NA [57,] -19 NA [58,] -18 NA [59,] -17 NA [60,] -16 NA [61,] -15 NA [62,] -14 NA [63,] -13 NA [64,] -12 NA [65,] -11 NA [66,] -10 NA [67,] -9 NA [68,] -8 NA [69,] -7 NA [70,] -6 NA [71,] -5 NA [72,] -4 NA [73,] -3 NA [74,] -2 NA [75,] -1 NA [76,] 0 62 [77,] 1 78 [78,] 2 98 [79,] 3 73 [80,] 4 57 [81,] 5 63 [82,] 6 56 [83,] 7 88 [84,] 8 77 [85,] 9 151 [86,] 10 165 [87,] 11 129 [88,] 12 78 [89,] 13 83 [90,] 14 63 [91,] 15 72 [92,] 16 68 [93,] 17 61 [94,] 18 89 [95,] 19 95 [96,] 20 74 [97,] 21 53 [98,] 22 77 [99,] 23 90 [100,] 24 106 [101,] 25 114 [102,] 26 113 [103,] 27 84 [104,] 28 59 [105,] 29 60 [106,] 30 77 [107,] 31 46 [108,] 32 91 [109,] 33 108 [110,] 34 111 [111,] 35 76 [112,] 36 75 [113,] 37 70 [114,] 38 61 [115,] 39 65 [116,] 40 61 [117,] 41 52 [118,] 42 94 [119,] 43 71 [120,] 44 67 [121,] 45 52 [122,] 46 86 [123,] 47 79 [124,] 48 97 [125,] 49 80 [126,] 50 101 [127,] 51 87 [128,] 52 53 [129,] 53 85 [130,] 54 79 [131,] 55 86 [132,] 56 104 [133,] 57 153 [134,] 58 128 [135,] 59 155 [136,] 60 148 [137,] 61 NA [138,] 62 NA [139,] 63 NA [140,] 64 NA [141,] 65 NA [142,] 66 NA [143,] 67 NA [144,] 68 NA [145,] 69 NA [146,] 70 NA [147,] 71 NA [148,] 72 NA [149,] 73 NA [150,] 74 NA [151,] 75 NA could anyone help me to with a function that would be able to calculate the sequence I require to bind to the initial sequence? thanks emma