Chrome: SVG container not rescaling responsively - css

I have an SVG that is effectively being used as a 'mask'; it's displayed over the top of another div with a background image so that the image peeks through the unfilled areas of the SVG. The SVG itself is responsive to the height of the document (rather than the width). This works fine so far.
However, I've just been made aware that if you resize the (Chrome) browser, the background image overflows out of the bounds of the masking SVG; however, if you refresh the resized page, everything appears as expected - it only occurs on resize, and only in Chrome (oh, and Opera too, apparently). Works as expected in FF and Safari.
I've included a demo here (and a jsFiddle) with an inline SVG, however it doesn't seem to matter if it's inline or with an <img /> tag - the results are the same.
It seems to be somehow related to the containing element; if I open up the inspector and set the containing element's padding to 0 after it goes screwy, then it seems to figure itself out and suddenly appear as expected; however if I include that rule in the loaded CSS then it makes no difference. I even tried triggering similar CSS properties on page resize via Javascript, but it hasn't made any difference.
Am I missing something, or have I stumbled across a bug?
#splash {
position: relative;
height: 100vh;
padding: 3rem;
overflow: hidden;
display: flex;
-webkit-box-align: center;
align-items: center;
background-color: #DDDDDD;
}
#logowrapper {
position: relative;
width: auto;
height: 60%;
margin: auto;
}
#logowrapper .kitten {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-image: url('http://placekitten.com/200/300');
background-size: cover;
}
#logowrapper svg {
position: relative;
width: auto;
height: 100%;
z-index: 4;
}
<div id="splash">
<div id="logowrapper">
<div class="kitten"></div>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 300" preserveAspectRatio="xMinYMin meet">
<defs/>
<g>
<path stroke="none" fill="#DDDDDD" d="M110.95 215.1 Q100 225.6 100 240.7 100 256.25 110.75 266.85 121.45 277.5 137 277.5 153.9 277.5 165.45 267.4 177 257.35 177 242.5 177 226.85 166.7 216.1 155.6 204.6 137.5 204.6 121.85 204.6 110.95 215.1 M82.9 206.15 L82.2 206.05 80.3 206.05 Q75.15 206.05 71.55 207.25 66.35 208.95 66.35 212.7 66.35 215.65 67.75 216.9 L69.25 218.45 Q69.25 220.6 67.05 223.4 64.85 226.1 64.05 226.1 L63.8 226.1 Q62.45 225.9 60.35 223.3 58.25 220.75 58.25 218.4 58.25 217.8 59.6 217.1 60.95 216.3 60.95 214.7 L60.85 213.3 Q60.35 210.15 57.05 208.5 53.7 206.9 50.15 206.9 L32.8 206.9 27.25 207.75 Q21.85 209.3 21.85 213.1 21.85 214.8 23.35 216.2 24.85 217.8 28.4 219.3 29.9 219.9 35.1 226.2 40.3 232.5 44.5 239.15 45.2 240.05 45.4 242.35 L45.6 248.15 45.4 255.5 45 261.5 Q45 263.1 42.8 264.65 38.2 267.8 38.2 269.6 38.2 274.8 45.2 275.9 L58.55 276.5 61.45 276.5 64.35 276.6 Q69.45 276.6 72.2 275.6 75.85 274.1 77.25 270.45 L77.45 269.1 Q77.45 267.2 75.15 265.6 70.45 262.25 70.45 259.55 L70.45 238.95 86.05 218.7 Q86.3 218.45 91.45 216.9 95.1 215.75 95.1 212.05 95.1 208.35 93.45 207.15 91.6 205.95 88.5 205.95 L85.65 206.05 82.9 206.15 M127.75 222.3 Q130.15 219.2 133.85 219.2 141.8 219.2 146.9 232 151 242.15 151 251.7 151 256.7 148.6 259.6 146.2 262.4 142.2 262.4 135.1 262.4 129.75 249.5 125.35 238.95 125.35 230.4 125.35 225.5 127.75 222.3 M127 174.1 Q127.35 173.5 128.35 173.5 132.6 173.5 132.6 178.95 132.6 183.25 129 183.25 127.35 183.25 126.95 181.7 126.7 180.85 126.7 178.2 L126.65 176.9 126.6 175.7 Q126.6 174.7 127 174.1 M126.85 160.15 Q127.2 159.3 128.05 159.3 131.5 159.3 131.5 164.2 131.5 168.75 127.95 168.75 127.1 168.75 126.8 167.9 126.45 167.1 126.45 165.75 L126.5 164.8 126.6 163.8 126.55 163.5 126.5 162.2 Q126.5 161 126.85 160.15 M111.95 158.35 Q112.35 159 113.1 159 114.4 159 115.05 161.55 115.65 164.15 115.65 168.15 115.65 173.9 114.65 179 113.65 184.1 112.3 184.1 111.75 184.1 111.55 184.55 L111.35 185.8 Q111.35 186.95 112.3 187.65 113.2 188.35 114.7 188.35 L119.6 188.2 124.9 188.05 129.2 188.2 133.15 188.35 Q139 188.35 142.5 185.45 145.95 182.6 145.95 177.7 145.95 173.8 142.8 171.8 139.6 169.85 139.6 169.4 L142 166.2 Q143.1 164.4 143.1 162.15 143.1 157.75 139.35 155.9 136.65 154.55 131.8 154.55 L127.55 154.65 121.75 154.75 118.8 154.65 114.9 154.55 Q113.4 154.55 112.45 155.25 111.5 155.95 111.5 157 111.5 157.75 111.95 158.35 M106.65 123.3 L103.7 123.4 97.65 123.4 95.55 123.65 Q95.05 123.9 95.05 124.6 95.05 125.15 95.75 125.45 96.4 125.7 96.6 126 97.15 127.2 97.15 131.75 L97.05 134.45 96.8 136.4 Q96.6 137.2 95.9 137.6 95.2 137.95 95.2 138.45 95.2 139.45 96.45 139.45 L106.35 139.45 108.1 139.65 109.05 139.7 Q109.8 139.7 110.55 137.9 L111.2 135.45 110.9 134.3 Q110.55 133.9 110.05 133.9 109.7 133.9 108.65 135.5 107.5 137.1 104.5 137.1 102.9 137.1 102.55 136.65 102.25 136.15 102.25 133.95 102.25 133 102.4 132.65 102.6 132.35 103.15 132.35 104.35 132.35 104.65 133.55 104.9 134.75 105.45 134.75 106.15 134.75 106.6 133.75 107 132.7 107 131.05 107 129.4 106.65 128.5 106.25 127.6 105.6 127.6 104.8 127.6 104.6 128.85 104.35 130.1 103.5 130.1 L102.3 129.95 Q102.05 129.8 102.05 129.05 L102.05 127.05 Q102.05 126.2 102.45 125.9 L104 125.65 Q107.05 125.65 108 127.2 L109 127.85 Q110.25 127.85 110.25 126.2 110.25 124.95 109.65 123.95 109.1 122.95 108.4 122.95 L106.65 123.3 M150.65 132.95 L149.4 132.85 148.85 132.5 Q148.85 132.05 149.45 130.75 150 129.5 150.4 129.5 L151.55 130.75 Q152.3 132.05 152.3 132.55 L151.85 132.85 150.65 132.95 M158.5 133.55 Q156.15 128.3 155.2 126.7 153 123.05 150.85 123.05 148.25 123.05 148.25 126 L147.2 129.6 Q146.05 132.8 144.95 134.8 143.55 137.4 142.8 137.4 142.3 137.4 142.1 137.7 141.95 137.95 141.95 138.35 141.95 139.1 142.75 139.4 L145.5 139.7 Q148.9 139.7 148.9 138.3 148.9 137.75 148.2 137.5 147.45 137.2 147.45 136.9 147.45 136.1 147.85 135.9 L149.95 135.65 150.55 135.65 152.8 135.85 Q153.55 136.05 153.55 136.75 L153.1 137.3 Q152.15 137.75 152.15 138.35 152.15 139.25 153.5 139.45 L157.4 139.7 160.8 139.3 Q161.8 138.95 161.8 138.05 161.8 137.25 160.95 137.25 160.2 137.25 158.5 133.55 M125.05 123.2 L122.1 123.6 Q121.05 124.05 121.05 124.8 121.05 125.6 121.55 125.8 122.3 126.15 122.65 127.1 L126.95 138.15 Q127.3 139.05 127.75 139.4 128.15 139.75 128.9 139.75 130.15 139.75 131.15 137.75 L132.5 134.15 Q133.15 132.2 133.65 132.2 134.25 132.2 134.95 134.15 L136.25 137.75 Q137.2 139.7 138.45 139.7 139.2 139.7 139.65 139.15 L140.85 136.8 144.35 127.65 Q144.95 126.15 145.5 125.6 146.2 125 146.2 124.6 146.2 123.15 143.5 123.15 141.8 123.15 141 123.5 140.25 123.8 140.25 124.5 140.25 125.25 141 125.55 141.75 125.85 141.75 126.25 L141.05 128.7 Q140.35 130.45 139.95 130.45 139.6 130.45 138.7 128.75 137.8 127.05 137.8 126.15 L138.1 125.55 138.8 124.55 Q138.8 123.85 137.8 123.5 L134.45 123.2 Q130 123.2 130 124.65 130 125.2 130.95 126.05 131.95 126.9 131.95 127.6 L131.6 129.15 Q131.15 130.7 130.5 130.7 130.1 130.7 129.3 128.55 128.55 126.6 128.55 126.15 L128.75 125.6 129.1 124.65 Q129.1 123.8 128.25 123.5 L125.05 123.2 M58.85 159.05 Q53.65 164.05 53.65 171.25 53.65 178.65 58.75 183.7 63.85 188.75 71.25 188.75 79.3 188.75 84.8 183.95 90.3 179.15 90.3 172.1 90.3 164.65 85.4 159.55 80.1 154.05 71.5 154.05 64.05 154.05 58.85 159.05 M69.75 161 Q73.55 161 76 167.1 77.95 171.95 77.95 176.5 77.95 178.85 76.8 180.25 75.65 181.6 73.75 181.6 70.35 181.6 67.8 175.45 65.7 170.4 65.7 166.35 65.7 164 66.85 162.5 68 161 69.75 161 M25.65 154.5 L24.4 154.2 Q21.85 154.2 19.85 157.7 18.1 160.75 18.1 163.25 18.1 164.7 18.8 165.85 19.45 167 20.65 167 22.7 167 24.8 164.3 26.9 161.6 27.55 161.6 28.6 161.6 29 162.95 29.4 164.35 29.4 166.75 L29.3 169.4 29.2 172.6 29 176.6 28.3 180.95 Q28.1 181.7 26.3 182.65 24.5 183.6 24.5 184.55 24.5 186.9 28.1 187.75 L34.9 188.3 Q40.5 188.3 42.7 187.3 44.95 186.35 44.95 184.7 44.95 183.35 43.15 182.65 41.4 182 41.2 181.25 40.55 178.55 40.4 177.05 L40.2 173 Q40.2 169 40.5 165.25 40.8 161.5 41.4 161.5 43.35 161.5 44.6 164.15 45.85 166.8 48.4 166.8 49.9 166.8 50.95 165.65 52 164.5 52 162.9 52 160.4 50.6 157.45 48.95 154.05 46.6 154.05 L46.3 154.05 45.35 154.35 44.15 154.7 26.95 154.8 25.65 154.5 M29.4 123.45 L28.55 123.45 Q26.1 123.45 25.05 123.95 24.2 124.35 24.2 125.1 24.2 125.45 24.65 125.8 25.65 126.55 25.75 127.3 L25.85 129.35 25.85 129.75 25.85 130.15 25.75 132.8 25.7 135.35 Q25.7 136.4 24.5 137.05 23.95 137.35 23.95 137.75 23.95 138.9 25.25 139.25 L27.9 139.5 28.65 139.5 31.45 139.3 Q32.9 139 32.9 138.2 32.9 137.65 32.2 136.95 L31.4 135.8 31.35 134.15 31.25 132.35 31.4 129.05 31.5 127.1 Q31.5 126.8 32.45 125.9 32.9 125.5 32.9 124.95 32.9 123.95 31.8 123.65 L29.4 123.45 M43.05 123.3 L41.3 123.1 Q38.5 123.1 36.6 124.65 34.7 126.25 34.7 128.6 34.7 130.8 36.75 132.3 37.7 133 40.5 134.2 42.55 135.1 42.55 135.75 42.55 136.25 42 136.55 L40.6 136.85 Q38.35 136.85 37.05 135.05 35.7 133.25 35.25 133.25 34.25 133.25 34.25 134.55 34.25 137.15 35.6 138.3 37.2 139.75 41.45 139.75 44.7 139.75 46.75 138.2 48.8 136.6 48.8 134.05 48.8 131.65 46.75 130.35 45.95 129.85 42.95 128.8 40.9 128.1 40.9 127.2 40.9 126.65 41.3 126.35 41.7 126.05 42.35 126.05 43.55 126.05 45.05 127.35 46.55 128.7 47.2 128.7 47.75 128.7 48.15 128.2 48.55 127.75 48.55 127.1 48.55 126.1 47.75 124.85 46.95 123.45 46 123.45 L45.4 123.6 44.9 123.75 43.05 123.3 M80 123.35 L77.15 123.6 Q75.65 123.95 75.65 125 75.65 125.55 76.15 125.75 L77.1 126.45 77.35 127.6 77.4 130.25 77.25 134.5 76.8 136.8 76 137.15 Q75.5 137.3 75.5 137.9 75.5 138.95 76.95 139.35 L79.6 139.6 82.45 139.3 Q84.05 138.9 84.05 138.05 L84.05 137.95 Q84.05 137.5 83.6 137.15 82.5 136.35 82.5 134.5 82.5 133.45 82.8 133.05 83.25 132.5 84.7 132.5 L86.4 132.7 Q86.75 132.9 86.75 133.45 L86.7 133.9 86.7 134.35 Q86.7 136.55 85.65 137.2 85.2 137.5 85.2 138.2 85.2 138.95 86.6 139.4 L89.1 139.7 91.4 139.6 Q93.75 139.3 93.75 138.05 93.75 137.5 93.25 137.3 92.25 136.85 92.25 132.5 92.25 126.5 93.45 125.75 94 125.4 94 124.85 94 124 92.65 123.6 L90.15 123.25 87.8 123.4 Q85.3 123.75 85.3 124.9 85.3 125.3 86.05 125.9 86.8 126.5 86.8 128.1 L86.65 129.45 Q86.5 129.75 85.8 129.75 L85.35 129.7 84.9 129.7 84.4 129.75 83.95 129.75 Q83.2 129.75 82.95 129.45 82.6 129.1 82.6 128.05 82.6 126.45 83.8 125.75 84.2 125.45 84.2 124.95 L84.2 124.85 Q84.1 123.85 82.65 123.5 L80 123.35 M62.25 123.35 L61.65 123.15 Q60.45 123.15 59.5 124.85 58.65 126.3 58.65 127.5 58.65 128.2 59 128.75 59.3 129.35 59.85 129.35 60.85 129.35 61.85 128 62.85 126.75 63.2 126.75 63.7 126.75 63.9 127.4 L64.05 129.2 64 130.45 64 132 63.9 133.95 63.55 136 62.6 136.85 Q61.75 137.3 61.75 137.75 61.75 138.9 63.45 139.3 L66.7 139.55 70.45 139.05 Q71.5 138.6 71.5 137.8 71.5 137.2 70.7 136.85 69.85 136.5 69.75 136.15 L69.35 134.15 69.25 132.2 Q69.25 130.3 69.4 128.5 69.55 126.7 69.85 126.7 70.75 126.7 71.35 127.95 71.95 129.25 73.2 129.25 73.9 129.25 74.4 128.65 74.9 128.1 74.9 127.35 74.9 126.15 74.25 124.75 73.45 123.1 72.35 123.1 L72.2 123.1 71.75 123.25 71.15 123.4 62.9 123.45 62.25 123.35 M24.6 90.45 Q21.7 90.45 21.7 94.35 21.7 102.15 25.7 105.65 30.55 110.05 43.2 110.05 53 110.05 59.2 105.3 65.35 100.55 65.35 92.95 65.35 85.7 59.2 81.75 56.8 80.25 47.7 77.15 41.55 75.05 41.55 72.35 41.55 70.65 42.8 69.75 44 68.85 46 68.85 49.6 68.85 54.05 72.8 58.5 76.8 60.5 76.8 62.2 76.8 63.35 75.4 64.5 74.05 64.5 72.05 64.5 69 62.2 65.25 59.7 61.15 56.95 61.15 56.25 61.15 55.15 61.6 L53.55 62.05 48 60.6 42.8 60 Q34.4 60 28.7 64.75 23 69.5 23 76.5 23 83.15 29.1 87.7 32 89.75 40.45 93.4 46.5 96 46.5 98 46.5 99.45 44.9 100.35 43.25 101.3 40.75 101.3 33.95 101.3 30 95.85 26.05 90.45 24.6 90.45 M24.1 34.7 Q24.1 33.75 24.95 33.75 26.55 33.75 26.55 36.05 26.55 38.25 24.6 38.25 24.2 38.25 24.1 38.1 23.95 37.9 23.95 37.5 L24.1 34.7 M19.6 31.3 Q16.95 31.3 16.95 32.7 16.95 33.2 17.5 33.45 18.7 33.95 18.7 37 L18.65 41.9 Q18.65 44.55 17.5 45.25 16.95 45.6 16.95 46.05 16.95 47.7 21.3 47.7 L24.6 47.35 Q25.6 47.05 25.6 46.25 25.6 45.7 25.1 45.4 24.1 44.8 24.1 42.25 L24.1 41.95 24.2 41.15 Q24.3 40.75 24.8 40.75 26.05 40.75 26.6 42.6 27.5 45.7 27.75 46.05 28.85 47.9 31.5 47.9 L34.15 47.45 Q35.15 46.95 35.15 46.15 35.15 45.6 34.35 45.3 33.5 45 33.4 43.9 33.1 41.6 32.1 40.55 31.2 39.55 30.2 39.2 L31.75 37.75 Q32.5 36.85 32.5 35.45 32.5 33.55 30.95 32.4 29.4 31.2 26.85 31.2 L24.05 31.4 22.35 31.45 21 31.35 19.6 31.3 M76.35 33.8 Q77.4 33.8 78 34.5 78.6 35.2 78.6 36.45 78.6 37.7 78.05 38.35 77.5 39 76.5 39 L75.7 38.8 75.45 38.25 75.45 34.25 Q75.45 33.8 76.35 33.8 M42.9 33.9 L44.45 33.65 Q47.5 33.65 48.45 35.2 48.85 35.85 49.45 35.85 50.7 35.85 50.7 34.2 50.7 32.95 50.1 31.95 49.55 30.95 48.85 30.95 L47.1 31.3 44.15 31.4 38.1 31.4 36 31.65 Q35.5 31.9 35.5 32.6 35.5 33.15 36.2 33.45 L37.05 34 Q37.6 35.2 37.6 39.75 L37.5 42.45 37.25 44.4 Q37.05 45.2 36.35 45.6 35.65 45.95 35.65 46.45 35.65 47.45 36.9 47.45 L46.8 47.45 48.55 47.65 49.5 47.7 Q50.25 47.7 51 45.9 L51.65 43.45 51.35 42.3 Q51 41.9 50.5 41.9 50.15 41.9 49.1 43.5 47.95 45.1 44.95 45.1 43.35 45.1 43 44.65 42.7 44.15 42.7 41.95 42.7 41 42.85 40.65 43.05 40.35 43.6 40.35 44.8 40.35 45.1 41.55 45.35 42.75 45.9 42.75 46.6 42.75 47.05 41.75 47.45 40.7 47.45 39.05 47.45 37.4 47.1 36.5 46.7 35.6 46.05 35.6 45.25 35.6 45.05 36.85 44.8 38.1 43.95 38.1 L42.75 37.95 Q42.5 37.8 42.5 37.05 L42.5 35.05 Q42.5 34.2 42.9 33.9 M55.05 32.65 Q53.15 34.25 53.15 36.6 53.15 38.8 55.2 40.3 56.15 41 58.95 42.2 61 43.1 61 43.75 61 44.25 60.45 44.55 L59.05 44.85 Q56.8 44.85 55.5 43.05 54.15 41.25 53.7 41.25 52.7 41.25 52.7 42.55 52.7 45.15 54.05 46.3 55.65 47.75 59.9 47.75 63.15 47.75 65.2 46.2 67.25 44.6 67.25 42.05 67.25 39.65 65.2 38.35 64.4 37.85 61.4 36.8 59.35 36.1 59.35 35.2 59.35 34.65 59.75 34.35 60.15 34.05 60.8 34.05 62 34.05 63.5 35.35 65 36.7 65.65 36.7 66.2 36.7 66.6 36.2 67 35.75 67 35.1 67 34.1 66.2 32.85 65.4 31.45 64.45 31.45 L63.85 31.6 63.35 31.75 61.5 31.3 59.75 31.1 Q56.95 31.1 55.05 32.65 M117.5 61.3 L111.75 61 Q107 61 104.5 61.75 100.8 62.8 100.8 65.6 100.8 66.9 102.85 68.15 104.25 68.9 104.25 69.75 L104.1 70.2 98.1 84.15 97.2 84.4 Q96.25 84.4 96.05 83.9 L90.55 70.55 90.5 70.2 Q90.5 69.45 91.95 68.65 93.6 67.7 93.6 65.9 93.6 62.45 89.2 61.65 L80.95 61 79.7 60.85 78.4 60.85 Q73.8 60.85 70.4 62.3 66.95 63.75 66.95 66.5 66.95 68.15 69.35 69.1 71.6 70.1 72.05 70.95 L76.25 80.65 83.75 98.3 Q87.8 107.75 88.35 107.75 88.85 108.9 90.2 109.55 91.5 110.25 92.95 110.25 96.4 110.25 97.5 107.85 98.4 107.85 104.85 94 110.9 80.85 115.05 70.55 115.75 68.9 118.05 68.35 120.4 67.8 120.4 65.45 120.4 61.95 117.5 61.3 M115.25 32.9 Q115.25 33.5 115.95 33.9 116.65 34.3 116.75 34.65 L116.9 35.5 116.95 36.45 Q116.95 37.9 116.25 37.9 115.9 37.9 115 37.2 114.45 36.75 112.85 35.3 L110.1 32.7 Q109.3 31.95 108.75 31.75 L107.5 31.5 107.2 31.5 106.55 31.5 104.15 31.8 Q102.9 32.2 102.9 33.1 102.9 33.5 103.5 33.85 L104.4 34.5 104.95 36.85 105.15 39.3 105 42 104.6 44.7 103.75 45.45 103.35 46.15 Q103.35 46.9 104.45 47.3 L106.6 47.65 Q108.3 47.65 109.2 47.15 109.9 46.8 110.05 46.05 110.05 45.65 109.65 45.3 L108.85 44.7 108.45 43.4 108.25 41.8 108.45 40.55 Q108.6 40.1 108.9 40.1 109.6 40.1 111.8 42.05 L115.65 45.7 Q117.8 47.65 118.5 47.65 119.25 47.65 119.6 46.5 119.9 45.4 119.9 41.25 L120 37.35 Q120.1 35.8 120.35 34.7 120.45 34.35 120.95 34.1 121.95 33.55 121.95 32.8 121.95 32 120.95 31.65 L119.3 31.45 118.9 31.45 118.75 31.45 118.7 31.45 118.4 31.45 116.45 31.7 Q115.25 32.05 115.25 32.9 M90.55 37 Q90.55 35.9 91.1 35.15 91.65 34.45 92.5 34.45 94.3 34.45 95.45 37.35 96.4 39.7 96.4 41.85 96.4 43 95.85 43.7 95.3 44.3 94.4 44.3 92.75 44.3 91.55 41.35 90.55 38.95 90.55 37 M83.9 36.35 Q83.9 34.1 82.2 32.65 80.5 31.25 77.75 31.25 L73.65 31.5 71.2 31.6 70.55 31.55 69.95 31.55 68.55 31.8 Q68.05 32 68.05 32.65 68.05 33.4 68.75 33.6 70.2 34 70.2 35.75 L70.2 43.2 Q70.2 44.95 69.05 45.5 68.5 45.75 68.5 46.2 68.5 47.7 72.7 47.7 77.15 47.7 77.15 46.15 77.15 45.8 76.35 45.25 75.45 44.65 75.45 43.85 L75.4 41.85 Q75.4 41.45 76.15 41.45 L76.85 41.5 77.8 41.6 Q80.5 41.6 82.2 40.15 83.9 38.65 83.9 36.35 M100 33.75 Q97.45 31.1 93.3 31.1 89.75 31.1 87.25 33.5 84.75 35.9 84.75 39.35 84.75 42.9 87.2 45.35 89.65 47.75 93.2 47.75 97.05 47.75 99.7 45.45 102.35 43.15 102.35 39.75 102.35 36.2 100 33.75 M139.25 33.8 Q140.25 34.55 140.35 35.3 L140.45 37.35 140.45 37.75 140.45 38.15 140.35 40.8 140.3 43.35 Q140.3 44.4 139.1 45.05 138.55 45.35 138.55 45.75 138.55 46.9 139.85 47.25 L142.5 47.5 143.25 47.5 146.05 47.3 Q147.5 47 147.5 46.2 147.5 45.65 146.8 44.95 146.1 44.3 146 43.8 L145.95 42.15 145.85 40.35 146 37.05 146.1 35.1 Q146.1 34.8 147.05 33.9 L147.5 32.95 Q147.5 31.95 146.4 31.65 L144 31.45 143.15 31.45 Q140.7 31.45 139.65 31.95 138.8 32.35 138.8 33.1 138.8 33.45 139.25 33.8 M136.45 32.85 Q135.65 31.45 134.7 31.45 L134.1 31.6 133.6 31.75 131.75 31.3 130 31.1 Q127.2 31.1 125.3 32.65 123.4 34.25 123.4 36.6 123.4 38.8 125.45 40.3 126.4 41 129.2 42.2 131.25 43.1 131.25 43.75 131.25 44.25 130.7 44.55 L129.3 44.85 Q127.05 44.85 125.75 43.05 124.4 41.25 123.95 41.25 122.95 41.25 122.95 42.55 122.95 45.15 124.3 46.3 125.9 47.75 130.15 47.75 133.4 47.75 135.45 46.2 137.5 44.6 137.5 42.05 137.5 39.65 135.45 38.35 134.65 37.85 131.65 36.8 129.6 36.1 129.6 35.2 129.6 34.65 130 34.35 130.4 34.05 131.05 34.05 132.25 34.05 133.75 35.35 135.25 36.7 135.9 36.7 136.45 36.7 136.85 36.2 137.25 35.75 137.25 35.1 137.25 34.1 136.45 32.85 M177.65 155.8 Q176.45 153.75 175 153.75 L171.4 154.4 165.2 154.7 152.6 154.7 148.3 155.15 Q147.25 155.65 147.25 157.15 147.25 158.35 148.65 158.9 150.05 159.45 150.4 160.1 151.6 162.6 151.6 172.1 L151.4 177.7 150.85 181.7 Q150.45 183.45 149 184.2 147.5 184.95 147.5 186 147.5 188.1 150.1 188.1 L170.8 188.1 174.4 188.45 176.35 188.6 Q178 188.6 179.55 184.85 180.85 181.7 180.85 179.75 180.85 178.3 180.2 177.4 179.55 176.5 178.5 176.5 177.75 176.5 175.5 179.85 173.2 183.25 166.9 183.25 163.55 183.25 162.85 182.25 162.2 181.25 162.2 176.6 162.2 174.65 162.55 173.95 162.95 173.3 164.05 173.3 166.65 173.3 167.2 175.8 167.75 178.3 168.9 178.3 170.35 178.3 171.25 176.2 172.15 174.1 172.15 170.65 172.15 167.2 171.35 165.3 170.55 163.4 169.15 163.4 167.55 163.4 167.1 166 166.65 168.65 164.85 168.65 L162.3 168.3 Q161.8 168 161.8 166.45 L161.85 162.3 Q161.85 160.5 162.65 159.9 163.4 159.35 165.85 159.35 172.2 159.35 174.15 162.55 175 163.95 176.25 163.95 178.85 163.95 178.85 160.5 178.85 157.9 177.65 155.8 M173.1 123.45 L172.65 123.45 170.65 123.7 Q169.45 124.1 169.45 124.95 169.45 125.65 169.8 125.9 L170.15 126.3 169.65 127.4 168.95 128 168.9 128 Q168.55 128 168.1 127.4 167.6 126.8 167.6 126.25 L167.95 125.95 168.25 125.4 168.2 125.1 Q168.1 124.4 167.35 124 166.6 123.65 165.75 123.65 L161.8 123.65 160.55 123.85 Q159.3 124.2 159.3 125.05 159.3 125.45 159.65 125.75 160 126.15 160.8 126.45 L162.35 128.05 164.45 131 164.7 131.75 164.75 133.05 164.7 134.75 164.6 136.1 164.1 136.85 Q163.05 137.55 163.05 137.95 163.05 139.15 164.65 139.4 L167.7 139.55 168.35 139.55 169 139.55 170.8 139.35 Q171.65 139 171.95 138.15 L172 137.85 Q172 137.4 171.5 137.05 170.4 136.3 170.4 135.65 L170.4 130.95 174 126.35 175.2 125.9 Q176.05 125.65 176.05 124.8 176.05 123.95 175.65 123.7 175.25 123.4 174.55 123.4 L173.9 123.45 173.25 123.45 173.1 123.45 M165.9 61 L164.2 61.35 161.45 62.1 154.65 60.35 Q151.4 59.55 149.2 59.55 139 59.55 130.85 67.65 122.7 75.7 122.7 85.05 122.7 96.6 130.45 103.5 138.15 110.4 150.5 110.4 164.5 110.4 170.3 101 L173.55 94.1 177.15 92.7 Q178.6 91.85 178.6 90.2 178.6 87 173.95 85.5 170.4 84.35 164.8 84.35 158.15 84.35 154.7 85.35 149.8 86.8 149.8 90.5 149.8 93.3 153.6 93.75 157.45 94.2 157.45 96.25 157.45 98.05 156.35 99.3 155.2 100.6 153.25 100.6 148.8 100.6 144.9 94.55 141.05 88.55 141.05 82.45 141.05 77.3 143.15 73.7 145.8 69.35 150.8 69.35 154.85 69.35 159.1 74.05 163.35 78.75 166.95 78.75 169.15 78.75 170.65 77 172.1 75.3 172.1 72.95 172.1 69.65 170.55 65.75 168.6 61 165.9 61 M165.3 31.5 L163.4 31.4 160.95 31.65 Q159.75 32 159.75 32.95 159.75 33.4 160.4 33.8 L160.9 34.35 160.85 34.5 158.85 39.15 158.55 39.2 158.15 39.05 156.3 34.6 156.3 34.5 Q156.3 34.25 156.8 33.95 157.35 33.65 157.35 33.05 157.35 31.9 155.85 31.65 L153.1 31.4 152.7 31.35 152.25 31.35 Q150.75 31.35 149.6 31.85 148.45 32.35 148.45 33.25 148.45 33.8 149.25 34.1 150 34.45 150.15 34.75 L151.55 37.95 154.05 43.85 155.6 47 Q155.75 47.4 156.2 47.6 L157.1 47.85 Q158.25 47.85 158.65 47.05 158.95 47.05 161.1 42.4 L164.5 34.6 Q164.7 34.05 165.5 33.85 166.25 33.7 166.25 32.9 166.25 31.75 165.3 31.5 M174.1 33.9 L175.65 33.65 Q178.7 33.65 179.65 35.2 L180.65 35.85 Q181.9 35.85 181.9 34.2 181.9 32.95 181.3 31.95 180.75 30.95 180.05 30.95 L178.3 31.3 175.35 31.4 169.3 31.4 167.2 31.65 Q166.7 31.9 166.7 32.6 166.7 33.15 167.4 33.45 168.05 33.7 168.25 34 168.8 35.2 168.8 39.75 L168.7 42.45 168.45 44.4 Q168.25 45.2 167.55 45.6 166.85 45.95 166.85 46.45 166.85 47.45 168.1 47.45 L178 47.45 179.75 47.65 180.7 47.7 Q181.45 47.7 182.2 45.9 182.85 44.4 182.85 43.45 182.85 42.75 182.55 42.3 182.2 41.9 181.7 41.9 181.35 41.9 180.3 43.5 179.15 45.1 176.15 45.1 174.55 45.1 174.2 44.65 173.9 44.15 173.9 41.95 173.9 41 174.05 40.65 174.25 40.35 174.8 40.35 176 40.35 176.3 41.55 176.55 42.75 177.1 42.75 177.8 42.75 178.25 41.75 178.65 40.7 178.65 39.05 178.65 37.4 178.3 36.5 177.9 35.6 177.25 35.6 176.45 35.6 176.25 36.85 176 38.1 175.15 38.1 L173.95 37.95 Q173.7 37.8 173.7 37.05 L173.7 35.05 Q173.7 34.2 174.1 33.9 M200 0 L200 300 0 300 0 0 200 0"/>
</g>
</svg>
</div>
</div>

If you want to use a responsive inline SVG in your HTML, the SVG shouldn't have width and height attributes.
Update:
Maybe It's a bug on Blink (or Webkit). And I tried to use a redraw hack.
https://jsfiddle.net/pbg1g4uv/2/
#logowrapper svg {
position: relative;
width: auto;
height: 100%;
z-index: 4;
animation: redraw 1s infinite;
}
#keyframes redraw {
from { min-width: 1px; }
to { min-width: 2px; }
}

Related

How can I organise and move row of data based on label matches?

I have raw data shown below. I'm trying to move a row of data that corresponds to a label it matches to a new location in the dataframe.
dat<-read.table(text='RowLabels col1 col2 col3 col4 col5 col6
L 24363.7 25944.9 25646.1 25335.4 23564.2 25411.5
610 411.4 439 437.3 436.9 420.7 516.9
1 86.4 113.9 103.5 113.5 80.3 129
2 102.1 99.5 96.3 100.4 99.5 86
3 109.7 102.2 100.2 112.9 92.3 123.8
4 88.9 87.1 103.6 102.5 93.6 134.1
5 -50.3 -40.2 -72.3 -61.4 -27 -22.7
6 -35.3 -9.3 25.3 -0.3 15.6 -27.3
7 109.9 85.8 80.7 69.3 66.4 94
181920 652.9 729.2 652.1 689.1 612.5 738.4
1 104.3 107.3 103.5 104.2 98.3 110.1
2 103.6 102.6 100.1 103.2 88.8 117.7
3 53.5 99.1 46.7 70.3 53.9 32.5
4 93.5 107.2 98.3 99.3 97.3 121.1
5 96.8 109.3 104 102.2 98.7 112.9
6 103.6 96.9 104.7 104.4 91.5 137.7
7 97.6 106.8 94.8 105.5 84 106.4
181930 732.1 709.6 725.8 729.5 554.5 873.1
1 118.4 98.8 102.3 102 101.9 115.8
2 96.7 103.3 104.6 105.2 81.9 128.7
3 96 98.2 99.4 97.9 69.8 120.6
4 100.7 101 103.6 106.6 59.6 136.2
5 106.1 103.4 104.7 104.8 76.1 131.8
6 105 102.1 103 108.3 81 124.7
7 109.2 102.8 108.2 104.7 84.2 115.3
N 3836.4 4395.8 4227.3 4567.4 4009.9 4434.6
610 88.1 96.3 99.6 92 90 137.6
1 88.1 96.3 99.6 92 90 137.6
181920 113.1 100.6 106.5 104.2 87.3 108.2
1 113.1 100.6 106.5 104.2 87.3 108.2
181930 111.3 99.1 104.5 115.5 103.6 118.8
1 111.3 99.1 104.5 115.5 103.6 118.8
',header=TRUE)
I want to match the values of the three N-prefix labels: 610, 181920 and 181930 with its corresponding L-prefix labels. Basically move that row of data into the L-prefix as a new row, labeled 0 or 8 for example. So, the result for label, 610 would look like:
RowLabels col1 col2 col3 col4 col5 col6
610 411.4 439 437.3 436.9 420.7 516.9
1 86.4 113.9 103.5 113.5 80.3 129
2 102.1 99.5 96.3 100.4 99.5 86
3 109.7 102.2 100.2 112.9 92.3 123.8
4 88.9 87.1 103.6 102.5 93.6 134.1
5 -50.3 -40.2 -72.3 -61.4 -27 -22.7
6 -35.3 -9.3 25.3 -0.3 15.6 -27.3
7 109.9 85.8 80.7 69.3 66.4 94
8 88.1 96.3 99.6 92 90 137.6
Is this possible? I tried searching and I found some resources pointing toward dplyr or tidyr or aggregate. But I can't find a good example that matches my case. How to combine rows based on unique values in R? and
Aggregate rows by shared values in a variable
library(dplyr)
library(zoo)
df <- dat %>%
filter(grepl("^\\d+$",RowLabels)) %>%
mutate(RowLabels_temp = ifelse(grepl("^\\d{3,}$",RowLabels), as.numeric(as.character(RowLabels)), NA)) %>%
na.locf() %>%
select(-RowLabels) %>%
distinct() %>%
group_by(RowLabels_temp) %>%
mutate(RowLabels_indexed = row_number()-1) %>%
arrange(RowLabels_temp, RowLabels_indexed) %>%
mutate(RowLabels_indexed = ifelse(RowLabels_indexed==0, RowLabels_temp, RowLabels_indexed)) %>%
rename(RowLabels=RowLabels_indexed) %>%
data.frame()
df <- df %>% select(-RowLabels_temp)
df
Output is
col1 col2 col3 col4 col5 col6 RowLabels
1 411.4 439.0 437.3 436.9 420.7 516.9 610
2 86.4 113.9 103.5 113.5 80.3 129.0 1
3 102.1 99.5 96.3 100.4 99.5 86.0 2
4 109.7 102.2 100.2 112.9 92.3 123.8 3
5 88.9 87.1 103.6 102.5 93.6 134.1 4
6 -50.3 -40.2 -72.3 -61.4 -27.0 -22.7 5
7 -35.3 -9.3 25.3 -0.3 15.6 -27.3 6
8 109.9 85.8 80.7 69.3 66.4 94.0 7
9 88.1 96.3 99.6 92.0 90.0 137.6 8
...
It sounds like you want to use the match() function, for example:
target<-c(the values of your target order)
df<-df[match(target, df$column_to_reorder),]

Padding out missing values with NAs

I have loop to analysis of 25 time series, In the analysis I need to get the mean of the individual columns for each station , for example the mean of all the Januaries, the same for all the Februaries, etc., etc. To complicate matters the time series are not all the same length, for example station 1 might run from 1900 to 1955 while station 2 might run from 1881 to 1945. So I need the mean of a Januaries of station 1, the mean of all Februaries of Station 1, etc., etc. and the same process for station 2 etc., etc. My times do not all start in January or end in December, but can start and finish in any month, each time series is individual. To get the colMeans, I need to change the time series to a matrix, but I need to pad out the empty spaces with NAs. Now how can I do that and put the function into the loop
Below is an example of my data
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1951 15.50 18.74 22.75 25.90 25.43 27.61
1952 27.60 27.72 27.63 24.38 20.34 17.74 17.90 20.57 23.13 25.60 26.41 26.98
1953 25.80 26.19 24.99 23.23 19.59 15.78 14.85 18.97 20.44 25.78 26.65 27.00
1954 26.25 26.97 25.33 23.16 20.47 15.47 15.64 18.33 22.71 26.71 25.77 25.94
1955 26.69 25.36 24.19 23.42 19.65 17.10 17.36 18.67 20.95 24.41 24.93 26.12
1956 26.02 26.48 25.81 23.91 20.78 17.40 17.48 19.96 21.06 25.44 26.16 25.92
1957 26.67 28.03 25.24 24.40 19.89 16.54 17.99 19.01 24.81 26.18 28.38 26.96
1958 25.90 26.49 24.90 24.67 21.36 16.19 16.29 17.20 22.18 24.52 29.13 26.65
1959 26.53 26.65 25.17 24.26 20.67 17.56 18.11 18.49 21.50 26.21 26.48 27.52
1960 27.25 26.04 26.58 22.80 19.41 17.16 15.57 20.24 22.86 26.68 25.71 27.58
1961 26.79 25.88 26.19 24.22 22.09 17.77 17.91 18.56 23.27 24.94 25.68 26.66
1962 27.03 28.11 26.05 23.81 18.79 17.32 16.04 19.23 23.14 27.57 27.37 27.09
1963 26.91 26.68 24.97 22.87 18.71 16.79 16.05 18.25 23.52 25.73 27.08 26.86
1964 28.63 28.04 28.16 23.98 19.78 15.40 14.98 18.32 22.88 25.60 26.55 25.23
1965 27.77 28.87 26.62 23.40 19.49 15.62 17.14 19.79 22.09 23.44 26.32 28.40
1966 29.68 26.63 25.50 23.13 19.49 18.65 17.69 19.32 22.12 23.88 27.37 27.75
1967 27.84 26.46 25.75 24.20 20.15 17.22 15.64 18.39 22.41 25.38 27.42 27.62
1968 30.27 27.91 26.32 22.56 19.86 14.16 17.07 19.76 22.42 26.05 24.61 26.38
1969 28.72 30.04 25.85 23.68 20.09 18.32 16.85 19.61 22.10 24.97 27.28 25.46
1970 29.62 27.24 26.62 23.34 20.20 16.95 17.40 20.23 24.21 24.74 27.25 28.71
1971 26.25 26.44 28.15 25.31 19.14 16.21 16.92 19.12 23.09 24.28 24.43 27.19
1972 26.64 26.07 25.17 24.13 19.45 15.83 16.14 18.45 22.74 24.98 25.54 30.09
1973 30.44 28.54 28.10 22.80 20.36 18.05 16.74 19.16 23.56 24.64 25.97 25.50
1974 27.46 26.52 25.44 22.36 19.79 16.83 16.70 19.89 21.39 26.22 25.84 25.93
1975 27.84 25.91 24.42 22.87 20.90 16.42 16.25 18.79 23.24 24.54 27.07 26.97
1976 26.05 26.33 24.95 22.07 18.42 16.88 15.79 17.24 23.01 25.26 27.65 29.15
1977 30.00 26.31 23.47 23.17 20.21 17.23 16.12 18.80 23.55 25.93 26.97 26.68
1978 25.99 26.36 26.31 22.49 19.72 15.88 15.99 21.64 23.57 24.68 24.78 26.47
1979 26.98 28.17 25.36 24.06 20.65 17.64 15.98 19.89 22.63 25.40 25.31 27.03
1980 27.74 28.05 25.47 23.72 20.55 15.96

(statistics) 2-way table normalization

I have a table like this.
X X2008 X2009 X2010 X2011 X2012 X2013 X2014 X2015
1 SU 103.27 105.2 99.7 106.7 96.7 108.4 88.7 73.67
2 BS 100.17 104.5 97.6 103.6 91.7 106.2 85.5 73.66
3 DG 101.00 102.5 98.9 101.1 91.2 106.2 80.9 75.67
4 IC 97.80 103.4 97.2 102.4 88.4 103.3 85.7 70.00
5 DJ 106.20 103.1 99.1 97.7 90.7 106.2 77.5 74.00
6 GJ 97.47 101.7 98.6 101.2 89.9 105.6 81.7 73.33
7 US 99.80 105.6 98.2 0.0 81.7 103.6 84.3 68.00
8 GG 98.13 105.7 98.6 103.7 92.2 105.2 85.9 73.66
9 GO 96.13 101.2 96.8 101.7 86.4 105.7 78.1 72.66
10 CB 104.20 105.2 101.5 100.3 88.3 106.2 78.8 72.00
11 CN 107.20 95.0 96.1 98.7 88.2 103.7 78.5 71.33
12 GB 98.87 102.0 95.3 100.2 87.2 104.2 78.5 70.33
13 GN 99.57 103.3 95.6 102.6 89.2 103.7 83.2 72.00
14 JB 99.60 96.2 98.2 96.2 86.2 101.7 84.5 71.34
15 JN 93.83 98.6 98.8 95.2 87.2 102.7 83.9 70.33
16 JJ 93.63 101.7 93.2 98.1 0.0 0.0 83.9 71.00
17 SJ 0.00 0.0 0.0 0.0 0.0 106.5 81.9 73.34
This is a test score that took place in some provinces of South Korea in each year.
The boundary of the test score was [0,110] until 2013, but it was changed to [0,100] in 2014.
My objective is to normalize the test score into some boundary or hopely some standardized region.
Maybe, I can first convert the scores among 2008 and 2013 into 100% scale, and subtract column mean and divide by standard deviation of each column to achieve this. But then, that is only standardized in each column.
Is there any possible way to normalize (or standardize) the test score as a whole?
By the way, the test score 0 means there was no test, so it must be ignored in the normalization process. And, this is csv format for your convenience..
,2008,2009,2010,2011,2012,2013,2014,2015
SU,103.27,105.2,99.7,106.7,96.7,108.4,88.7,73.67
BS,100.17,104.5,97.6,103.6,91.7,106.2,85.5,73.66
DG,101,102.5,98.9,101.1,91.2,106.2,80.9,75.67
IC,97.8,103.4,97.2,102.4,88.4,103.3,85.7,70
DJ,106.2,103.1,99.1,97.7,90.7,106.2,77.5,74
GJ,97.47,101.7,98.6,101.2,89.9,105.6,81.7,73.33
US,99.8,105.6,98.2,0,81.7,103.6,84.3,68
GG,98.13,105.7,98.6,103.7,92.2,105.2,85.9,73.66
GO,96.13,101.2,96.8,101.7,86.4,105.7,78.1,72.66
CB,104.2,105.2,101.5,100.3,88.3,106.2,78.8,72
CN,107.2,95,96.1,98.7,88.2,103.7,78.5,71.33
GB,98.87,102,95.3,100.2,87.2,104.2,78.5,70.33
GN,99.57,103.3,95.6,102.6,89.2,103.7,83.2,72
JB,99.6,96.2,98.2,96.2,86.2,101.7,84.5,71.34
JN,93.83,98.6,98.8,95.2,87.2,102.7,83.9,70.33
JJ,93.63,101.7,93.2,98.1,0,0,83.9,71
SJ,0,0,0,0,0,106.5,81.9,73.34
I think the best would probably need be to convert columns 2 to 6 i.e. the ones in the range [0-110] to the range of [0-100]. In this way everything will be in the same scale. In order to do this:
Data:
df <- read.table(header=T, text=' X X2008 X2009 X2010 X2011 X2012 X2013 X2014 X2015
1 SU 103.27 105.2 99.7 106.7 96.7 108.4 88.7 73.67
2 BS 100.17 104.5 97.6 103.6 91.7 106.2 85.5 73.66
3 DG 101.00 102.5 98.9 101.1 91.2 106.2 80.9 75.67
4 IC 97.80 103.4 97.2 102.4 88.4 103.3 85.7 70.00
5 DJ 106.20 103.1 99.1 97.7 90.7 106.2 77.5 74.00
6 GJ 97.47 101.7 98.6 101.2 89.9 105.6 81.7 73.33
7 US 99.80 105.6 98.2 0.0 81.7 103.6 84.3 68.00
8 GG 98.13 105.7 98.6 103.7 92.2 105.2 85.9 73.66
9 GO 96.13 101.2 96.8 101.7 86.4 105.7 78.1 72.66
10 CB 104.20 105.2 101.5 100.3 88.3 106.2 78.8 72.00
11 CN 107.20 95.0 96.1 98.7 88.2 103.7 78.5 71.33
12 GB 98.87 102.0 95.3 100.2 87.2 104.2 78.5 70.33
13 GN 99.57 103.3 95.6 102.6 89.2 103.7 83.2 72.00
14 JB 99.60 96.2 98.2 96.2 86.2 101.7 84.5 71.34
15 JN 93.83 98.6 98.8 95.2 87.2 102.7 83.9 70.33
16 JJ 93.63 101.7 93.2 98.1 0.0 0.0 83.9 71.00
17 SJ 0.00 0.0 0.0 0.0 0.0 106.5 81.9 73.34')
You could do:
df[2:6] <- lapply(df[2:6], function(x) {
x / 110 * 100
})
Essentially you divide by 120 which is the max in [0-110] in order to convert to the range between [0-1] and then multiply by 100 to convert that in the range between [0-100].
Output:
> df
X X2008 X2009 X2010 X2011 X2012 X2013 X2014 X2015
1 SU 93.88182 95.63636 90.63636 97.00000 87.90909 108.4 88.7 73.67
2 BS 91.06364 95.00000 88.72727 94.18182 83.36364 106.2 85.5 73.66
3 DG 91.81818 93.18182 89.90909 91.90909 82.90909 106.2 80.9 75.67
4 IC 88.90909 94.00000 88.36364 93.09091 80.36364 103.3 85.7 70.00
5 DJ 96.54545 93.72727 90.09091 88.81818 82.45455 106.2 77.5 74.00
6 GJ 88.60909 92.45455 89.63636 92.00000 81.72727 105.6 81.7 73.33
7 US 90.72727 96.00000 89.27273 0.00000 74.27273 103.6 84.3 68.00
8 GG 89.20909 96.09091 89.63636 94.27273 83.81818 105.2 85.9 73.66
9 GO 87.39091 92.00000 88.00000 92.45455 78.54545 105.7 78.1 72.66
10 CB 94.72727 95.63636 92.27273 91.18182 80.27273 106.2 78.8 72.00
11 CN 97.45455 86.36364 87.36364 89.72727 80.18182 103.7 78.5 71.33
12 GB 89.88182 92.72727 86.63636 91.09091 79.27273 104.2 78.5 70.33
13 GN 90.51818 93.90909 86.90909 93.27273 81.09091 103.7 83.2 72.00
14 JB 90.54545 87.45455 89.27273 87.45455 78.36364 101.7 84.5 71.34
15 JN 85.30000 89.63636 89.81818 86.54545 79.27273 102.7 83.9 70.33
16 JJ 85.11818 92.45455 84.72727 89.18182 0.00000 0.0 83.9 71.00
17 SJ 0.00000 0.00000 0.00000 0.00000 0.00000 106.5 81.9 73.34
And now you can compare between the years. Also, as you will notice zeros will remain zeros.

Animating SVG path with a clipPath using CSS

I thought I was doing something pretty trivial; animating a masked shape within an SVG, but it has utterly confounded me.
I have a relatively simple setup: an SVG with a defined clipPath and a path that uses said mask. Statically, this works exactly as expected - the clipPath masks the pattern I'm using. However, I was intending to animate the path so that it swoops in nicely, creating a nice text effect:
The first issue I encountered was that I couldn't use left or top in CSS to manipulate the position of path. I found a thread here that suggested using transform: translate(100px, 100px); which ostensibly seems to work. However, as soon as I move my path, the actual clipMask moves with it so that the whole thing appears off-centre.
To an extent I can kinda see how this might make sense, but coming from a Flash background I'm used to my masks staying still while I move the masked element.
I've set up a jsFiddle to illustrate the issue, and here's a code snippet:
body {
font-family: Trebuchet MS, san-serif;
}
#helvetica {
width: 100%;
background-color: pink;
}
#helvetica svg path#pattern {
left: -300px;
/*transform: translate(-300px, 0);*/
}
<div id="helvetica">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="550" height="80" viewbox="0 0 550 80">
<defs>
<clipPath id="myMask">
<path fill="#FF00CC" d="M55.7 28 L61.6 28 61.6 38.25 72.4 38.25 72.4 28 78.3 28 78.3 54.75 72.4 54.75 72.4 43.2 61.6 43.2 61.6 54.75 55.7 54.75 55.7 28 M104.6 28 L109.9 28 109.9 54.75 104.6 54.75 104.6 28 M87.75 41.25 Q87.35 42.2 87.3 43 L95.95 43 Q95.6 40.95 94.65 39.9 93.65 38.85 91.75 38.85 90.05 38.85 89.1 39.55 88.15 40.3 87.75 41.25 M91.9 34.85 Q94.35 34.85 96.2 35.8 98 36.75 99.2 38.35 100.4 39.95 100.9 42 101.45 44.1 101.3 46.35 L87.3 46.35 Q87.4 48.85 88.65 50.1 89.85 51.3 92.05 51.25 93.7 51.25 94.85 50.45 96 49.7 96.25 48.75 L100.95 48.75 Q99.8 52.15 97.5 53.7 95.2 55.3 91.9 55.3 88.8 55.25 86.6 53.95 84.4 52.7 83.2 50.4 82 48.1 82 45.05 82 42.15 83.25 39.85 84.45 37.5 86.7 36.2 88.9 34.85 91.9 34.85 M133.95 39.85 Q135.15 37.5 137.4 36.2 139.6 34.85 142.6 34.85 145.05 34.85 146.9 35.8 148.7 36.75 149.9 38.35 151.1 39.95 151.6 42 152.15 44.1 152 46.35 L138 46.35 Q138.1 48.85 139.35 50.1 140.55 51.3 142.75 51.25 144.4 51.25 145.55 50.45 146.7 49.7 146.95 48.75 L151.65 48.75 Q150.5 52.15 148.2 53.7 145.9 55.3 142.6 55.3 139.5 55.25 137.3 53.95 135.1 52.7 133.9 50.4 132.7 48.1 132.7 45.05 132.7 42.15 133.95 39.85 M139.8 39.55 Q138.85 40.3 138.45 41.25 138.05 42.2 138 43 L146.65 43 Q146.3 40.95 145.35 39.9 144.35 38.85 142.45 38.85 140.75 38.85 139.8 39.55 M126.1 35.35 L131.4 35.35 124.85 54.75 118.9 54.75 112.3 35.35 117.85 35.35 121.95 48.6 122 48.6 126.1 35.35 M178.6 39.9 Q179.75 37.55 181.95 36.2 184.15 34.85 187.35 34.85 189.65 34.85 191.65 35.65 193.65 36.45 194.95 38.05 196.25 39.7 196.45 42.2 L191.25 42.2 Q191 40.55 189.95 39.7 188.95 38.85 187.3 38.85 185.6 38.85 184.6 39.85 183.6 40.8 183.2 42.25 182.75 43.7 182.75 45.15 182.75 46.6 183.15 48 183.6 49.35 184.55 50.3 185.5 51.25 187.2 51.25 189.05 51.25 190.1 50.2 191.15 49.15 191.4 47.35 L196.55 47.35 Q196 51.2 193.55 53.25 191.1 55.25 187.2 55.3 184.3 55.25 182.1 54 179.9 52.75 178.65 50.5 177.45 48.25 177.45 45.35 177.45 42.3 178.6 39.9 M168.5 28 L173.8 28 173.8 32.35 168.5 32.35 168.5 28 M168.5 35.35 L173.8 35.35 173.8 54.75 168.5 54.75 168.5 35.35 M165.75 35.35 L165.75 38.95 161.85 38.95 161.85 48.5 Q161.85 49.85 162.3 50.3 162.8 50.8 164.1 50.8 L164.95 50.75 165.75 50.65 165.75 54.8 164.25 54.95 162.65 54.95 159.6 54.65 Q158.25 54.25 157.4 53.25 156.55 52.3 156.55 50.35 L156.55 38.95 153.3 38.95 153.3 35.35 156.55 35.35 156.55 29.55 161.85 29.55 161.85 35.35 165.75 35.35 M238.75 43.7 L227.55 43.7 227.55 54.75 221.65 54.75 221.65 28 240.45 28 240.45 32.9 227.55 32.9 227.55 39.1 238.75 39.1 238.75 43.7 M204.95 47.2 Q204.05 47.8 204 49.25 204.05 50.7 205 51.2 205.95 51.75 207.3 51.7 208.85 51.7 209.7 51.2 L211 49.9 211.5 48.45 211.6 47.25 211.6 45.25 Q210.9 45.8 209.65 46 L207.15 46.4 Q205.9 46.6 204.95 47.2 M204.2 35.4 L208.4 34.85 211.4 35.05 Q212.85 35.25 214.15 35.85 215.35 36.45 216.15 37.5 216.9 38.6 216.95 40.35 L216.95 50.45 217.05 52.95 Q217.25 54.15 217.6 54.75 L212.2 54.75 211.95 53.85 211.8 52.9 Q210.55 54.2 208.8 54.75 L205.3 55.3 Q203.45 55.3 201.95 54.65 200.45 54.05 199.6 52.75 198.7 51.45 198.7 49.45 198.75 47.3 199.65 46.1 200.6 44.9 202.1 44.35 203.6 43.75 205.3 43.6 L208.4 43.2 210.7 42.55 Q211.6 42.1 211.6 41 211.6 39.9 211.1 39.35 210.65 38.75 209.9 38.55 L208.15 38.4 Q206.6 38.4 205.7 39.1 204.75 39.75 204.6 41.35 L199.3 41.35 Q199.5 38.85 200.8 37.45 202.15 36 204.2 35.4 M275.4 28 L280.7 28 280.7 54.75 275.4 54.75 275.4 28 M265.7 28 L271 28 271 54.75 265.7 54.75 265.7 28 M256.2 35.35 L261.5 35.35 261.5 54.75 256.45 54.75 256.45 52.05 256.35 52.05 Q255.3 53.7 253.7 54.5 252.15 55.3 250.4 55.3 247.6 55.25 246.05 54.25 244.5 53.3 243.9 51.5 243.3 49.7 243.35 47.3 L243.35 35.35 248.65 35.35 248.65 46.35 Q248.65 48.7 249.45 49.9 250.25 51.1 252.05 51.1 254.25 51.1 255.2 49.8 256.2 48.45 256.2 45.55 L256.2 35.35 M315.95 35.35 L319.85 35.35 319.85 38.95 315.95 38.95 315.95 48.5 Q315.95 49.85 316.4 50.3 316.9 50.8 318.2 50.8 L319.05 50.75 319.85 50.65 319.85 54.8 318.35 54.95 316.75 54.95 313.7 54.65 Q312.35 54.25 311.5 53.25 310.65 52.3 310.65 50.35 L310.65 38.95 307.4 38.95 307.4 35.35 310.65 35.35 310.65 29.55 315.95 29.55 315.95 35.35 M294.65 27.35 Q297.5 27.3 299.95 28.2 302.35 29.1 303.85 31 305.35 32.9 305.4 35.95 L299.7 35.95 Q299.6 34.35 298.85 33.45 298.15 32.6 297 32.25 L294.4 31.9 292.5 32.2 Q291.6 32.5 291 33.15 290.35 33.85 290.35 34.95 290.3 35.95 290.9 36.55 291.55 37.1 293.25 37.65 L298.35 39 300.4 39.55 Q301.7 39.95 303.05 40.8 304.4 41.65 305.3 43.1 306.25 44.55 306.3 46.8 306.3 49.3 305 51.2 303.75 53.15 301.25 54.25 298.8 55.35 295.15 55.4 292.9 55.4 290.85 54.8 288.8 54.25 287.2 53.1 285.6 51.95 284.65 50.15 283.75 48.35 283.75 45.85 L289.45 45.85 Q289.45 47.65 290.3 48.75 291.1 49.8 292.45 50.3 L295.35 50.8 297.65 50.55 Q298.85 50.3 299.7 49.55 300.55 48.85 300.6 47.5 300.55 46.05 299.4 45.3 298.25 44.5 296.45 44 L292.65 43.05 288.8 41.75 Q287 40.9 285.85 39.4 284.7 37.9 284.65 35.45 284.65 33.4 285.5 31.85 286.4 30.35 287.85 29.35 289.3 28.35 291.05 27.85 L294.65 27.35 M350.5 45.1 Q350.45 46.7 350.9 48.1 351.35 49.5 352.4 50.35 353.4 51.25 355.1 51.25 356.85 51.25 357.85 50.35 358.9 49.5 359.3 48.1 359.75 46.7 359.7 45.1 359.75 43.55 359.3 42.1 358.85 40.7 357.8 39.75 356.8 38.85 355.05 38.85 353.35 38.85 352.35 39.75 351.3 40.65 350.9 42.1 350.45 43.5 350.5 45.1 M356.25 34.85 Q359.25 34.85 361.25 36.3 363.2 37.75 364.1 40.1 365.05 42.45 365.05 45.25 365.05 47.9 364.1 50.15 363.15 52.4 361.25 53.85 359.4 55.25 356.55 55.3 354.8 55.3 353.25 54.55 351.7 53.8 350.75 52.35 L350.65 52.35 350.65 61.6 345.35 61.6 345.35 35.35 350.4 35.35 350.4 37.85 350.5 37.85 Q351.45 36.3 352.95 35.55 354.45 34.85 356.25 34.85 M327.15 45.1 Q327.15 46.65 327.6 48.05 328 49.45 329 50.35 330.05 51.25 331.85 51.25 333.65 51.25 334.7 50.35 335.75 49.45 336.15 48.05 336.6 46.65 336.55 45.1 336.6 43.5 336.15 42.1 335.75 40.65 334.7 39.75 333.65 38.85 331.85 38.85 330.05 38.85 329 39.75 328 40.65 327.6 42.1 327.15 43.5 327.15 45.1 M326.55 36.1 Q328.8 34.85 331.85 34.85 334.9 34.85 337.15 36.1 339.4 37.35 340.65 39.65 341.9 41.95 341.9 45.1 341.9 48.2 340.65 50.45 339.4 52.75 337.15 54 334.9 55.25 331.85 55.3 328.8 55.25 326.55 54 324.3 52.75 323.05 50.45 321.85 48.2 321.85 45.1 321.85 41.95 323.05 39.65 324.3 37.35 326.55 36.1 M368.5 49 L374.4 49 374.4 54.75 368.5 54.75 368.5 49"/>
</clipPath>
</defs>
<path id="pattern" clip-path="url(#myMask)" fill="#333333" d="M493.35 13.9 L450.6 66.4 446.1 66.4 488.85 13.9 493.35 13.9 M488.1 66.4 L483.6 66.4 526.35 13.9 530.85 13.9 488.1 66.4 M455.85 13.9 L413.1 66.4 408.6 66.4 451.35 13.9 455.85 13.9 M470.85 13.9 L428.1 66.4 423.6 66.4 466.35 13.9 470.85 13.9 M431.1 13.9 L388.35 66.4 383.85 66.4 426.6 13.9 431.1 13.9 M425.85 13.9 L383.1 66.4 378.6 66.4 421.35 13.9 425.85 13.9 M437.1 13.9 L394.35 66.4 389.85 66.4 432.6 13.9 437.1 13.9 M444.6 13.9 L401.85 66.4 397.35 66.4 440.1 13.9 444.6 13.9 M377.85 66.4 L14.15 66.4 56.9 13.9 420.6 13.9 377.85 66.4"/>
</svg>
</div>
<p>
Uncomment the <code>transform</code> line in the CSS to see the effect - the mask moves <em>with</em> the masked shape.
</p>
Is there another way to achieve the same effect? Note that this will be placed over a photographic image, so an animated GIF isn't going to cut it, and it must be scalable without loss of quality (hence, SVG).
If you don't want the clip to move, all you have to do is put it on something that doesn't move.
body {
font-family: Trebuchet MS, san-serif;
}
#helvetica {
width: 100%;
background-color: pink;
}
#helvetica svg path#pattern {
left: -300px;
transform: translate(-300px, 0);
}
<div id="helvetica">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="550" height="80" viewbox="0 0 550 80">
<defs>
<clipPath id="myMask">
<path fill="#FF00CC" d="M55.7 28 L61.6 28 61.6 38.25 72.4 38.25 72.4 28 78.3 28 78.3 54.75 72.4 54.75 72.4 43.2 61.6 43.2 61.6 54.75 55.7 54.75 55.7 28 M104.6 28 L109.9 28 109.9 54.75 104.6 54.75 104.6 28 M87.75 41.25 Q87.35 42.2 87.3 43 L95.95 43 Q95.6 40.95 94.65 39.9 93.65 38.85 91.75 38.85 90.05 38.85 89.1 39.55 88.15 40.3 87.75 41.25 M91.9 34.85 Q94.35 34.85 96.2 35.8 98 36.75 99.2 38.35 100.4 39.95 100.9 42 101.45 44.1 101.3 46.35 L87.3 46.35 Q87.4 48.85 88.65 50.1 89.85 51.3 92.05 51.25 93.7 51.25 94.85 50.45 96 49.7 96.25 48.75 L100.95 48.75 Q99.8 52.15 97.5 53.7 95.2 55.3 91.9 55.3 88.8 55.25 86.6 53.95 84.4 52.7 83.2 50.4 82 48.1 82 45.05 82 42.15 83.25 39.85 84.45 37.5 86.7 36.2 88.9 34.85 91.9 34.85 M133.95 39.85 Q135.15 37.5 137.4 36.2 139.6 34.85 142.6 34.85 145.05 34.85 146.9 35.8 148.7 36.75 149.9 38.35 151.1 39.95 151.6 42 152.15 44.1 152 46.35 L138 46.35 Q138.1 48.85 139.35 50.1 140.55 51.3 142.75 51.25 144.4 51.25 145.55 50.45 146.7 49.7 146.95 48.75 L151.65 48.75 Q150.5 52.15 148.2 53.7 145.9 55.3 142.6 55.3 139.5 55.25 137.3 53.95 135.1 52.7 133.9 50.4 132.7 48.1 132.7 45.05 132.7 42.15 133.95 39.85 M139.8 39.55 Q138.85 40.3 138.45 41.25 138.05 42.2 138 43 L146.65 43 Q146.3 40.95 145.35 39.9 144.35 38.85 142.45 38.85 140.75 38.85 139.8 39.55 M126.1 35.35 L131.4 35.35 124.85 54.75 118.9 54.75 112.3 35.35 117.85 35.35 121.95 48.6 122 48.6 126.1 35.35 M178.6 39.9 Q179.75 37.55 181.95 36.2 184.15 34.85 187.35 34.85 189.65 34.85 191.65 35.65 193.65 36.45 194.95 38.05 196.25 39.7 196.45 42.2 L191.25 42.2 Q191 40.55 189.95 39.7 188.95 38.85 187.3 38.85 185.6 38.85 184.6 39.85 183.6 40.8 183.2 42.25 182.75 43.7 182.75 45.15 182.75 46.6 183.15 48 183.6 49.35 184.55 50.3 185.5 51.25 187.2 51.25 189.05 51.25 190.1 50.2 191.15 49.15 191.4 47.35 L196.55 47.35 Q196 51.2 193.55 53.25 191.1 55.25 187.2 55.3 184.3 55.25 182.1 54 179.9 52.75 178.65 50.5 177.45 48.25 177.45 45.35 177.45 42.3 178.6 39.9 M168.5 28 L173.8 28 173.8 32.35 168.5 32.35 168.5 28 M168.5 35.35 L173.8 35.35 173.8 54.75 168.5 54.75 168.5 35.35 M165.75 35.35 L165.75 38.95 161.85 38.95 161.85 48.5 Q161.85 49.85 162.3 50.3 162.8 50.8 164.1 50.8 L164.95 50.75 165.75 50.65 165.75 54.8 164.25 54.95 162.65 54.95 159.6 54.65 Q158.25 54.25 157.4 53.25 156.55 52.3 156.55 50.35 L156.55 38.95 153.3 38.95 153.3 35.35 156.55 35.35 156.55 29.55 161.85 29.55 161.85 35.35 165.75 35.35 M238.75 43.7 L227.55 43.7 227.55 54.75 221.65 54.75 221.65 28 240.45 28 240.45 32.9 227.55 32.9 227.55 39.1 238.75 39.1 238.75 43.7 M204.95 47.2 Q204.05 47.8 204 49.25 204.05 50.7 205 51.2 205.95 51.75 207.3 51.7 208.85 51.7 209.7 51.2 L211 49.9 211.5 48.45 211.6 47.25 211.6 45.25 Q210.9 45.8 209.65 46 L207.15 46.4 Q205.9 46.6 204.95 47.2 M204.2 35.4 L208.4 34.85 211.4 35.05 Q212.85 35.25 214.15 35.85 215.35 36.45 216.15 37.5 216.9 38.6 216.95 40.35 L216.95 50.45 217.05 52.95 Q217.25 54.15 217.6 54.75 L212.2 54.75 211.95 53.85 211.8 52.9 Q210.55 54.2 208.8 54.75 L205.3 55.3 Q203.45 55.3 201.95 54.65 200.45 54.05 199.6 52.75 198.7 51.45 198.7 49.45 198.75 47.3 199.65 46.1 200.6 44.9 202.1 44.35 203.6 43.75 205.3 43.6 L208.4 43.2 210.7 42.55 Q211.6 42.1 211.6 41 211.6 39.9 211.1 39.35 210.65 38.75 209.9 38.55 L208.15 38.4 Q206.6 38.4 205.7 39.1 204.75 39.75 204.6 41.35 L199.3 41.35 Q199.5 38.85 200.8 37.45 202.15 36 204.2 35.4 M275.4 28 L280.7 28 280.7 54.75 275.4 54.75 275.4 28 M265.7 28 L271 28 271 54.75 265.7 54.75 265.7 28 M256.2 35.35 L261.5 35.35 261.5 54.75 256.45 54.75 256.45 52.05 256.35 52.05 Q255.3 53.7 253.7 54.5 252.15 55.3 250.4 55.3 247.6 55.25 246.05 54.25 244.5 53.3 243.9 51.5 243.3 49.7 243.35 47.3 L243.35 35.35 248.65 35.35 248.65 46.35 Q248.65 48.7 249.45 49.9 250.25 51.1 252.05 51.1 254.25 51.1 255.2 49.8 256.2 48.45 256.2 45.55 L256.2 35.35 M315.95 35.35 L319.85 35.35 319.85 38.95 315.95 38.95 315.95 48.5 Q315.95 49.85 316.4 50.3 316.9 50.8 318.2 50.8 L319.05 50.75 319.85 50.65 319.85 54.8 318.35 54.95 316.75 54.95 313.7 54.65 Q312.35 54.25 311.5 53.25 310.65 52.3 310.65 50.35 L310.65 38.95 307.4 38.95 307.4 35.35 310.65 35.35 310.65 29.55 315.95 29.55 315.95 35.35 M294.65 27.35 Q297.5 27.3 299.95 28.2 302.35 29.1 303.85 31 305.35 32.9 305.4 35.95 L299.7 35.95 Q299.6 34.35 298.85 33.45 298.15 32.6 297 32.25 L294.4 31.9 292.5 32.2 Q291.6 32.5 291 33.15 290.35 33.85 290.35 34.95 290.3 35.95 290.9 36.55 291.55 37.1 293.25 37.65 L298.35 39 300.4 39.55 Q301.7 39.95 303.05 40.8 304.4 41.65 305.3 43.1 306.25 44.55 306.3 46.8 306.3 49.3 305 51.2 303.75 53.15 301.25 54.25 298.8 55.35 295.15 55.4 292.9 55.4 290.85 54.8 288.8 54.25 287.2 53.1 285.6 51.95 284.65 50.15 283.75 48.35 283.75 45.85 L289.45 45.85 Q289.45 47.65 290.3 48.75 291.1 49.8 292.45 50.3 L295.35 50.8 297.65 50.55 Q298.85 50.3 299.7 49.55 300.55 48.85 300.6 47.5 300.55 46.05 299.4 45.3 298.25 44.5 296.45 44 L292.65 43.05 288.8 41.75 Q287 40.9 285.85 39.4 284.7 37.9 284.65 35.45 284.65 33.4 285.5 31.85 286.4 30.35 287.85 29.35 289.3 28.35 291.05 27.85 L294.65 27.35 M350.5 45.1 Q350.45 46.7 350.9 48.1 351.35 49.5 352.4 50.35 353.4 51.25 355.1 51.25 356.85 51.25 357.85 50.35 358.9 49.5 359.3 48.1 359.75 46.7 359.7 45.1 359.75 43.55 359.3 42.1 358.85 40.7 357.8 39.75 356.8 38.85 355.05 38.85 353.35 38.85 352.35 39.75 351.3 40.65 350.9 42.1 350.45 43.5 350.5 45.1 M356.25 34.85 Q359.25 34.85 361.25 36.3 363.2 37.75 364.1 40.1 365.05 42.45 365.05 45.25 365.05 47.9 364.1 50.15 363.15 52.4 361.25 53.85 359.4 55.25 356.55 55.3 354.8 55.3 353.25 54.55 351.7 53.8 350.75 52.35 L350.65 52.35 350.65 61.6 345.35 61.6 345.35 35.35 350.4 35.35 350.4 37.85 350.5 37.85 Q351.45 36.3 352.95 35.55 354.45 34.85 356.25 34.85 M327.15 45.1 Q327.15 46.65 327.6 48.05 328 49.45 329 50.35 330.05 51.25 331.85 51.25 333.65 51.25 334.7 50.35 335.75 49.45 336.15 48.05 336.6 46.65 336.55 45.1 336.6 43.5 336.15 42.1 335.75 40.65 334.7 39.75 333.65 38.85 331.85 38.85 330.05 38.85 329 39.75 328 40.65 327.6 42.1 327.15 43.5 327.15 45.1 M326.55 36.1 Q328.8 34.85 331.85 34.85 334.9 34.85 337.15 36.1 339.4 37.35 340.65 39.65 341.9 41.95 341.9 45.1 341.9 48.2 340.65 50.45 339.4 52.75 337.15 54 334.9 55.25 331.85 55.3 328.8 55.25 326.55 54 324.3 52.75 323.05 50.45 321.85 48.2 321.85 45.1 321.85 41.95 323.05 39.65 324.3 37.35 326.55 36.1 M368.5 49 L374.4 49 374.4 54.75 368.5 54.75 368.5 49"/>
</clipPath>
</defs>
<g clip-path="url(#myMask)">
<path id="pattern" fill="#333333" d="M493.35 13.9 L450.6 66.4 446.1 66.4 488.85 13.9 493.35 13.9 M488.1 66.4 L483.6 66.4 526.35 13.9 530.85 13.9 488.1 66.4 M455.85 13.9 L413.1 66.4 408.6 66.4 451.35 13.9 455.85 13.9 M470.85 13.9 L428.1 66.4 423.6 66.4 466.35 13.9 470.85 13.9 M431.1 13.9 L388.35 66.4 383.85 66.4 426.6 13.9 431.1 13.9 M425.85 13.9 L383.1 66.4 378.6 66.4 421.35 13.9 425.85 13.9 M437.1 13.9 L394.35 66.4 389.85 66.4 432.6 13.9 437.1 13.9 M444.6 13.9 L401.85 66.4 397.35 66.4 440.1 13.9 444.6 13.9 M377.85 66.4 L14.15 66.4 56.9 13.9 420.6 13.9 377.85 66.4"/>
</g>
</svg>
</div>

cor() giving a missing value error on small matrix but not large matrix

I'm trying to use cor() to return the most correlated elements in order of their correlation. I wrote this function adapting cor() to do it and it works perfectly, but only when I run it on a big input. When I try and run it on a small input, I get a missing value where TRUE/FALSE needed error and I don't understand why?
Here is an example of my input data:
This can be directly copied into R(printed via write.table):
"Col2" "Col3" "Col4" "Col5" "Col6"
"Market Capitalization" NA NA 17082.69 17879.8 16266.11
"Cash & Equivalents" NA NA 747 132 394
"Preferred & Other" NA NA 0 0 0
"Total Debt" NA NA 12379 11982 11309
"Enterprise Value" NA NA 28714.69 29729.8 27181.11
"Total Revenue" 2896.75 3461.25 2818 3184 2901
"Growth % YoY" -0.15 0.68 1.7 3.44 -0.48
"Gross Profit" NA NA 1874 2080 1981
"Margin %" NA NA 66.5 65.33 68.29
"EBITDA" 758 1074 641 777 699
"Margin %1" 26.17 31.03 22.75 24.4 24.1
"Net Income Before XO" 214.5 410 172 192 207
"Margin %2" 7.4 11.85 6.1 6.03 7.14
"Adjusted EPS" 0.7 1.42 0.59 1.07 0.69
"Growth % YoY1" 0.72 -1.67 -3.28 5.94 -6.76
"Cash from Operations" 375.79 812.21 991 -84 961
"Capital Expenditures" NA NA -660 -676 -608
"Free Cash Flow" NA NA 331 -760 353
"Adjusted Price" 2094.66 3689.2 3805.62 3588.42 3582.4
This is the mycor() function I wrote
mycor<-function(dataset, relative.to=19, neg.cor=0){
#This takes the dataset (as a matrix) and computes the best correleted value
#and returns the row (variable ID) that is the most strongly correlated
#to the variable row referenced by relative.to. Use neg.cor = 1 for neg correlation
if(neg.cor == 0){
best.cor <- -1.0 #Have to get better correlation then this
best.cor.row <- integer() #The row with the best correlation
all.cor <- numeric() #The correlation for everything else
index <- 1 #The index for the all.cor array
for(i in 1:nrow(dataset)){
if(i != relative.to){ #No self correlation
temp.cor <- cor(dataset[i,], dataset[relative.to,], use = "na.or.complete")
all.cor[index] <- temp.cor
index <- index+1 #I wish the ++ opperator worked in R...
cat(best.cor)
pause()
if(temp.cor > best.cor){ #This remembers the best seen cor value
best.cor <- temp.cor
best.cor.row <- i
} #End inner if
} #End outter if
} #End for loop
}else{
best.cor <- 1.0 #Have to get better correlation then this
best.cor.row <- integer() #The row with the best correlation
all.cor <- numeric() #The correlation for everything else
index <- 1 #The index for the all.cor array
for(i in 1:nrow(dataset)){
if(i != relative.to){ #No self correlation
temp.cor <- cor(dataset[i,], dataset[relative.to,], use = "na.or.complete")
all.cor[index] <- temp.cor
index <- index+1 #I wish the ++ opperator worked in R...
if(temp.cor < best.cor){ #This remembers the worst seen cor value
best.cor <- temp.cor
best.cor.row <- i
} #End inner if
} #End outter if
} #End for loop
} #End else
return(list(all.cor = all.cor, best.cor.row = best.cor.row))
)
When I try and run this I get: Error in if (temp.cor > best.cor) { : missing value where TRUE/FALSE needed. The part about this that is strange, is that the mycor function works perfectly and gives no error when I give it a larger chunk of the same data set.
This is the larger chunk of the same data set.
This can also be copied into R(printed via write.table):
"Col2" "Col3" "Col4" "Col5" "Col6" "Col7" "Col8" "Col9" "Col10" "Col11" "Col12" "Col13" "Col14" "Col15" "Col16" "Col17" "Col18" "Col19" "Col20" "Col21" "Col22" "Col23" "Col24" "Col25" "Col26" "Col27" "Col28" "Col29" "Col30" "Col31" "Col32" "Col33" "Col34" "Col35" "Col36" "Col37" "Col38" "Col39" "Col40" "Col41" "Col42" "Col43" "Col44" "Col45" "Col46" "Col47" "Col48" "Col49" "Col50" "Col51" "Col52" "Col53" "Col54" "Col55" "Col56" "Col57" "Col58" "Col59" "Col60" "Col61" "Col62" "Col63" "Col64" "Col65" "Col66" "Col67" "Col68" "Col69" "Col70" "Col71" "Col72" "Col73" "Col74" "Col75" "Col76" "Col77" "Col78" "Col79" "Col80" "Col81" "Col82" "Col83" "Col84" "Col85" "Col86" "Col87" "Col88" "Col89" "Col90" "Col91" "Col92" "Col93" "Col94" "Col95" "Col96" "Col97" "Col98" "Col99" "Col100" "Col101" "Col102" "Col103" "Col104" "Col105" "Col106" "Col107" "Col108" "Col109" "Col110" "Col111"
"Market Capitalization" NA NA 17082.69 17879.8 16266.11 17540.1 18214.39 17110.13 18167.87 16700.24 15592.71 14824.06 14455.42 13685.56 12168.31 12550.1 12771.45 11273.2 10284.48 10863.21 10655.99 11750.74 10671.37 10818.32 13288.42 12558.8 12221.79 13213.51 12375.92 11854.12 10942.65 10689.79 11364.1 11887.9 11426.1 10249.34 10609.99 10167.51 9600.1 10001.68 9713.38 9184.3 9730.33 8249.64 9160.61 8586.38 8894.55 8908.81 11887.9 11426.1 10249.34 10609.99 10167.51 9600.1 10001.68 9713.38 9184.3 9730.33 8249.64 9160.61 8586.38 8894.55 8908.81 8566.69 8641.04 8444.84 7867.83 8163.04 7238.2 6279.55 6173.33 7376.47 9048.75 10095.35 10351.52 12311.04 12006.02 10785.58 11009.16 9655.09 7990.1 6918.52 7050.24 6844.2 6520.75 6873.11 7489.61 7459.85 7136.58 6930.38 6401.43 6048.8 5843.01 6224.43 6840.76 7529.23 8452.46 8247.48 8132.72 7632.03 7339.11 6549.2 6165.26 6535.8 5793.52 5621.57 5877.31 5391.98 4792.51 5362.35
"Cash & Equivalents" NA NA 747 132 394 69 1381 769 648 398 492 516 338 198 178 87 260 75 311 651 74 68 1757 144 210 192 186 157 94 234 63 177 81 119 818 477 26 70 487 55 49 49 60 62 117.86 83.4 59.2 108.34 119 818 477 26 70 487 55 49 49 60 62 117.86 83.4 59.2 108.34 271.35 432.14 41.63 59.57 94.83 72.81 37.66 73.6 485.05 188.94 291.14 57.5 102.29 153.82 105.01 198.26 183.46 269.87 12.23 94.9 106.88 117.28 57.37 103.23 342.29 429.89 48.49 111.39 245.22 360.74 80.65 205.1 36.76 203.96 143.32 74.33 282.45 349.66 384.84 238.24 317.86 315.65 291.01 185.21 353.33 160.33 160.31
"Preferred & Other" NA NA 0 0 0 0 0 0 213 213 213 213 213 213 213 213 213 213 213 213 213 213 213 257 256 255 255 254 254 254 255 255 255 254 255 255 252 252 253 254 255 221 222 221 221.47 221.13 221.2 220.79 254 255 255 252 252 253 254 255 221 222 221 221.47 221.13 221.2 220.79 222.09 212.56 249.61 212.56 249.61 212.56 212.56 212.56 249.61 212.56 212.56 212.56 249.61 318.02 318.02 318.02 318.02 322.34 322.42 322.54 322.65 322.74 322.77 322.84 639.92 639.98 640.13 640.24 640.31 640.39 640.47 640.54 640.73 640.89 640.95 641.09 641.25 645.87 634.99 635.05 635.18 637.51 637.73 638.05 638.15 640.53 640.77
"Total Debt" NA NA 12379 11982 11309 11111 11873 11073 10675 10676 10678 11144 10683 11526 11020 11027 10599 10773 10366 10699 10094 9751 9480 9363 9282 9213 8653 8943 8815 8968 8487 8162 8205 7687 7868 7498 7219 7245 7336 7432 7094 6968 6682 7000 6841.23 6584.25 6374.14 6264.74 7687 7868 7498 7219 7245 7336 7432 7094 6968 6682 7000 6841.23 6584.25 6374.14 6264.74 6234.03 6249.6 6448.51 6100.6 6011.55 5693.56 5536.13 5276.01 5449.52 4792.08 4881.68 4471.08 4312.4 4410.61 4480.08 4437.33 4758.17 4432.04 4532.28 4466.59 4387.54 4313.86 4316.43 4316.66 4146.02 4175.36 4082.33 4085.09 4089.16 4116.98 3970.11 3972.46 3827.89 3850.12 3927.94 3722.68 3709.36 3804.58 3658.69 3885.52 3667.45 3734.29 3737 3615.16 3492.38 3374.62 3229.81
"Enterprise Value" NA NA 28714.69 29729.8 27181.11 28582.1 28706.39 27414.13 28407.87 27191.24 25991.71 25665.06 25013.42 25226.56 23223.31 23703.1 23323.45 22184.2 20552.48 21124.21 20888.99 21646.74 18607.37 20294.32 22616.42 21834.8 20943.79 22253.51 21350.92 20842.12 19621.65 18929.79 19743.1 19709.9 18731.1 17525.34 18054.99 17594.51 16702.1 17632.68 17013.38 16324.3 16574.33 15408.64 16105.45 15308.35 15430.68 15286 19709.9 18731.1 17525.34 18054.99 17594.51 16702.1 17632.68 17013.38 16324.3 16574.33 15408.64 16105.45 15308.35 15430.68 15286 14751.46 14671.06 15101.34 14121.44 14329.37 13071.51 11990.59 11588.31 12590.55 13864.46 14898.46 14977.66 16770.77 16580.82 15478.67 15566.25 14547.82 12474.62 11760.98 11744.46 11447.51 11040.07 11454.93 12025.88 11903.5 11522.02 11604.35 11015.38 10533.05 10239.65 10754.35 11248.66 11961.09 12739.51 12673.05 12422.15 11700.18 11439.9 10458.04 10447.58 10520.58 9849.67 9705.29 9945.31 9169.17 8647.34 9072.61
"Total Revenue" 2896.75 3461.25 2818 3184 2901 3438 2771 3078 2915 3629 2993 3349 3140 3707 3017 3462 3273 3489 2845 3423 2998 3858 3149 3577 3228 3579 2957 3357 2649 3441 2555 3317 3107 3337 2395 2800 2181 2734 2164 2685 2279 2801 2176 2570 2057.03 2539.49 1848 2056 3337 2395 2800 2181 2734 2164 2685 2279 2801 2176 2570 2057.03 2539.49 1848 2056 1942.6 2627.56 2112.22 2886.26 2250.13 2820.78 2041.89 2318.59 1963.38 2346.24 1479.08 1776.59 1617.34 2061.62 1561.04 1853.05 1720.06 2011.03 1504.01 1886.15 1632.3 1920.34 1539.73 1867.36 1528.38 1879.88 1459.85 1668.79 1461.25 1821.99 1392.09 1697.76 1483.61 1799.69 1396.01 1586.08 1478.81 1717.88 1280.11 1456.11 1342.73 1720.3 1330.65 1479.39 1367.21 1613.83 1263.27
"Growth % YoY" -0.15 0.68 1.7 3.44 -0.48 -5.26 -7.42 -8.09 -7.17 -2.1 -0.8 -3.26 -4.06 6.25 6.05 1.14 9.17 -9.56 -9.65 -4.31 -7.13 7.8 6.49 6.55 21.86 4.01 15.73 1.21 -14.74 3.12 6.68 18.46 42.46 22.06 10.67 4.28 -4.3 -2.39 -0.55 4.47 10.79 10.3 17.75 25 5.89 -3.35 -12.51 -28.77 22.06 10.67 4.28 -4.3 -2.39 -0.55 4.47 10.79 10.3 17.75 25 5.89 -3.35 -12.51 -28.77 -13.67 -6.85 3.44 24.48 14.6 20.23 38.05 30.51 21.4 13.81 -5.25 -4.13 -5.97 2.52 3.79 -1.75 5.38 4.72 -2.32 1.01 6.8 2.15 5.47 11.9 4.59 3.18 4.87 -1.71 -1.51 1.24 -0.28 7.04 0.32 4.76 9.05 8.93 10.13 -0.14 -3.8 -1.57 -1.79 6.6 5.33 -1.02 NA NA NA
"Gross Profit" NA NA 1874 2080 1981 2393 1934 1993 1846 2244 1794 2000 1942 2103 1723 1826 1700 1979 1558 1551 1459 1531 1420 1588 1478 1595 1317 1506 1273 1554 1202 1322 1179 1460 1097 1217 916 1285 980 1169 1066 1349 975 1157 1024.93 1317.57 980 1091 1460 1097 1217 916 1285 980 1169 1066 1349 975 1157 1024.93 1317.57 980 1091 1052.71 1368.8 1091.61 1236.41 991.8 1374.86 1043.29 1236.87 1129.87 1507.31 998.19 1190.69 1151.22 1475.08 1025.84 1170.8 1115.9 1438.56 981.96 1159.37 1094.25 1401.25 1001.2 1198.64 1079.65 1405.45 984.46 1196.22 1086.13 1415.37 998.06 1177.1 1086.53 1381.01 971.41 1118.91 1055.19 1331.37 947.22 1036.88 991.58 1301.1 921.48 994.97 967.89 1217.32 848.39
"Margin %" NA NA 66.5 65.33 68.29 69.6 69.79 64.75 63.33 61.84 59.94 59.72 61.85 56.73 57.11 52.74 51.94 56.72 54.76 45.31 48.67 39.68 45.09 44.39 45.79 44.57 44.54 44.86 48.06 45.16 47.05 39.86 37.95 43.75 45.8 43.46 42 47 45.29 43.54 46.77 48.16 44.81 45.02 49.83 51.88 53.03 53.06 43.75 45.8 43.46 42 47 45.29 43.54 46.77 48.16 44.81 45.02 49.83 51.88 53.03 53.06 54.19 52.09 51.68 42.84 44.08 48.74 51.09 53.35 57.55 64.24 67.49 67.02 71.18 71.55 65.72 63.18 64.88 71.53 65.29 61.47 67.04 72.97 65.02 64.19 70.64 74.76 67.44 71.68 74.33 77.68 71.7 69.33 73.24 76.74 69.58 70.55 71.35 77.5 74 71.21 73.85 75.63 69.25 67.26 70.79 75.43 67.16
"EBITDA" 758 1074 641 777 699 1091 711 794 684 978 617 844 708 916 640 696 625 885 569 611 567 586 520 702 596 715 510 694 547 670 467 564 423 717 411 533 274 624 367 497 458 669 334 485 388.44 693.3 384 487 717 411 533 274 624 367 497 458 669 334 485 388.44 693.3 384 487 445 695.27 439.32 538.75 377.16 666.39 492.65 526.86 446.87 748.34 331.51 492.91 430.87 760.5 313.33 474.78 434.79 751.92 280.96 463.41 390.79 712.97 313.14 490.27 368.26 711.24 307.36 506.85 383.64 721.41 317.3 474.34 363.04 678.27 279.09 400.41 320.03 637.82 281.47 340.21 297.39 610.07 247.48 300.27 305.15 561.67 203.06
"Margin %1" 26.17 31.03 22.75 24.4 24.1 31.73 25.66 25.8 23.46 26.95 20.61 25.2 22.55 24.71 21.21 20.1 19.1 25.37 20 17.85 18.91 15.19 16.51 19.63 18.46 19.98 17.25 20.67 20.65 19.47 18.28 17 13.61 21.49 17.16 19.04 12.56 22.82 16.96 18.51 20.1 23.88 15.35 18.87 18.88 27.3 20.78 23.69 21.49 17.16 19.04 12.56 22.82 16.96 18.51 20.1 23.88 15.35 18.87 18.88 27.3 20.78 23.69 22.91 26.46 20.8 18.67 16.76 23.62 24.13 22.72 22.76 31.9 22.41 27.74 26.64 36.89 20.07 25.62 25.28 37.39 18.68 24.57 23.94 37.13 20.34 26.25 24.09 37.83 21.05 30.37 26.25 39.59 22.79 27.94 24.47 37.69 19.99 25.25 21.64 37.13 21.99 23.36 22.15 35.46 18.6 20.3 22.32 34.8 16.07
"Net Income Before XO" 214.5 410 172 192 207 440 214 280 193 386 168 314 236 353 186 229 205 339 153 183 163 185 283 303 209 313 154 261 205 234 129 183 148 290 121 184 55 253 92 158 50 260 69 157 123.03 286.54 101 169 290 121 184 55 253 92 158 50 260 69 157 123.03 286.54 101 169 128.51 280.74 104.07 182.51 49.48 283.27 72.14 191.53 124.96 339.41 69.8 180.05 135.23 351.55 66.51 176.45 143.61 355.04 47.56 166.61 120.15 327.99 71.42 188.48 113.12 333.3 76.4 201.03 117.88 339.87 87.21 189.31 117.29 324.84 62.45 153.94 100.63 309.44 77.54 116.48 92.2 303.36 64.65 106.7 121.1 263.26 49.06
"Margin %2" 7.4 11.85 6.1 6.03 7.14 12.8 7.72 9.1 6.62 10.64 5.61 9.38 7.52 9.52 6.17 6.61 6.26 9.72 5.38 5.35 5.44 4.8 8.99 8.47 6.47 8.75 5.21 7.77 7.74 6.8 5.05 5.52 4.76 8.69 5.05 6.57 2.52 9.25 4.25 5.88 2.19 9.28 3.17 6.11 5.98 11.28 5.47 8.22 8.69 5.05 6.57 2.52 9.25 4.25 5.88 2.19 9.28 3.17 6.11 5.98 11.28 5.47 8.22 6.62 10.68 4.93 6.32 2.2 10.04 3.53 8.26 6.36 14.47 4.72 10.13 8.36 17.05 4.26 9.52 8.35 17.65 3.16 8.83 7.36 17.08 4.64 10.09 7.4 17.73 5.23 12.05 8.07 18.65 6.26 11.15 7.91 18.05 4.47 9.71 6.8 18.01 6.06 8 6.87 17.63 4.86 7.21 8.86 16.31 3.88
"Adjusted EPS" 0.7 1.42 0.59 1.07 0.69 1.44 0.61 1.01 0.74 1.33 0.57 0.99 0.69 1.32 0.51 0.93 0.67 1.16 0.48 0.78 0.72 0.98 0.42 0.87 0.71 1.2 0.58 1.03 0.78 0.92 0.51 0.86 0.59 1.17 0.48 0.75 0.49 1.08 0.38 0.69 0.65 1.16 0.29 0.72 0.56 1.33 0.46 0.78 1.17 0.48 0.75 0.49 1.08 0.38 0.69 0.65 1.16 0.29 0.72 0.56 1.33 0.46 0.78 0.59 1.3 0.48 0.84 0.52 1.4 0.33 0.88 0.57 1.5 0.3 0.76 0.56 1.49 0.26 0.73 0.59 1.49 0.18 0.69 0.49 1.38 0.28 0.78 0.44 1.38 0.29 0.82 0.47 1.41 0.33 0.77 0.46 1.35 0.23 0.62 0.39 1.3 0.3 0.47 0.36 1.29 0.24 0.43 0.49 1.11 0.18
"Growth % YoY1" 0.72 -1.67 -3.28 5.94 -6.76 8.27 7.02 2.02 7.25 0.76 11.76 6.45 2.99 13.79 6.25 19.23 -6.94 18.37 14.29 -10.34 1.41 -18.33 -27.59 -15.53 -8.97 30.43 13.73 19.77 32.2 -21.37 6.25 14.67 20.41 8.33 26.32 8.7 -24.62 -6.9 31.03 -4.17 16.07 -12.78 -36.96 -7.69 -5.08 2.31 -4.17 -7.14 8.33 26.32 8.7 -24.62 -6.9 31.03 -4.17 16.07 -12.78 -36.96 -7.69 -5.08 2.31 -4.17 -7.14 13.46 -7.14 45.45 -4.55 -8.77 -6.67 10 15.79 1.79 0.67 13.64 4.11 -5.08 -0.07 44.44 5.89 20.41 8.05 -34.72 -11.62 11.36 0 -3.45 -4.88 -6.38 -2.13 -12.12 6.49 2.17 4.44 43.48 24.19 17.95 3.85 -23.33 31.91 8.33 0.78 25 9.3 -26.53 16.22 33.33 -23.21 NA NA NA
"Cash from Operations" 375.79 812.21 991 -84 961 391 845 402 976 572 1227 362 1407 179 794 1 997 26 798 645 581 -1237 733 563 630 109 346 481 710 -162 224 593 177 581 -346 389 525 164 490 152 766 218 492 -58 735.49 285 369 146 581 -346 389 525 164 490 152 766 218 492 -58 735.49 285 369 146 490.18 387.73 254.59 141.41 215.82 279.84 489.5 199.17 -325.31 -66.66 280.22 256.65 718.82 438.66 302.05 244.37 -52.38 647.78 53.19 258.9 294.29 359.1 267.8 184.51 310.07 585.52 233.75 145.31 426.63 480.57 187.86 270.34 236.08 472.92 243.13 69.8 261.19 291.41 285.57 77.33 283.64 328.4 309.68 11.95 357.21 141.59 357.15
"Capital Expenditures" NA NA -660 -676 -608 -478 -635 -523 -542 -503 -629 -460 -599 -548 -551 -465 -719 -531 -595 -529 -785 -584 -608 -547 -638 -519 -485 -482 -583 -480 -537 -420 -619 -385 -426 -390 -431 -439 -308 -373 -448 -356 -404 -317 -593.69 -310 -392 -340 -385 -426 -390 -431 -439 -308 -373 -448 -356 -404 -317 -593.69 -310 -392 -340 -302.22 -394.08 -274.8 -228.02 -75.57 -274.36 -684.94 -207.41 -211.95 -218.98 -157.07 -127.56 -210.59 -156.81 -150.58 -127.3 -226.32 -145.55 -171.37 -140.37 -244.12 -167.92 -185.35 -142.94 -239.55 -165.98 -166.25 -147.38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
"Free Cash Flow" NA NA 331 -760 353 -87 210 -121 434 69 598 -98 808 -369 243 -464 278 -505 203 116 -204 -1821 125 16 -8 -410 -139 -1 127 -642 -313 173 -442 196 -772 -1 94 -275 182 -221 318 -138 88 -375 141.79 -25 -23 -194 196 -772 -1 94 -275 182 -221 318 -138 88 -375 141.79 -25 -23 -194 187.96 -6.35 -20.21 -86.61 140.26 5.47 -195.45 -8.24 -537.26 -285.64 123.15 129.09 508.23 281.85 151.46 117.07 -278.7 502.23 -118.18 118.53 50.17 191.18 82.45 41.57 70.51 419.54 67.49 -2.08 426.63 480.57 187.86 270.34 236.08 472.92 243.13 69.8 261.19 291.41 285.57 77.33 283.64 328.4 309.68 11.95 357.21 141.59 357.15
"Adjusted Price" 2094.66 3689.2 3805.62 3588.42 3582.4 3885.75 3523.13 3554.9 3420.27 3141.36 2984.19 2838.81 2760.09 2517.44 2447.56 2403.89 2188.98 1960.8 1952.2 2033.87 2099.97 1993.98 2043.36 2296.42 2201.73 2277.15 2301.5 2203.47 2086.87 1938.95 2019.34 2002.47 2048.12 1881.97 1817.17 1807.02 1664.57 1659.78 1717.25 1585.27 1589.9 1506.13 1534.98 1531.24 1498.21 1528.96 1418.46 1431.1 1343.43 1244.04 1194.62 1076.93 1058.66 960.76 1112.69 1322.69 1414.59 1442.28 1545.6 1364.27 1305.46 1231.15 1022.23 869.37 796.9 820.22 762.84 715.9 756.11 816.37 731.97 705.73 657.84 628.55 571.47 624.67 651.89 676.63 759.77 742.27 734.39 657.44 619.61 569.84 524.2 510.26 475.43 449.8 441.27 409.34 383 413.34 441.72 435.71 419.07 385.87 356.85 346.15 326.97 318.45 323.72 314.18 313.22 300.88 329.3 315.1 312.34 279.11 163.47 NA
The larger chunk works perfectly, but I need to be able to check the correlation on the smaller sections. I'm really new to R so it might be easy, but I've read the boards here and the r manuals and can't find it.
In your example above, your code fails on the first (smaller) data set because row 3 consists only of 0's and NA's, so it has a standard deviation of 0 and so its correlation with any other row will return NA, since computing correlation involves dividing the sample covariance by the sample standard deviation of each vector. It doesn't happen in the larget example because row 3 has sufficient variation to have a non-zero standard deviation.
However, your approach seems a bit convoluted. If you want to compute the correlation between a single row in the matrix and all other rows, sorted by correlation, then you can use cor() on the transposed matrix and sort the result, for example:
mycor <- function(dataset, relative.to=19) {
mat <- t(dataset)
cors <- cor(mat, mat[, relative.to], use="na.or.complete")
cors[order(drop(cors)), ]
}
mycor(dataset)

Resources