[R] cbind
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Tue Apr 14 14:56:40 CEST 2009
Yes, indeed!
Best,
Dimitris
Mike Lawrence wrote:
> Unfortunately Dimitris' solution fails in the face of NA padding on
> both sides of the numeric data, as in Emma's original example.
>
> x <- c(rep(NA, 20), sample(100, 25), rep(NA,20))
>
>
> On Tue, Apr 14, 2009 at 9:40 AM, Dimitris Rizopoulos
> <d.rizopoulos at erasmusmc.nl> wrote:
>> 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
>>
>> ______________________________________________
>> 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.
>>
>
>
>
--
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
More information about the R-help
mailing list