body {
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30.000000pt' height='30.000000pt' viewBox='0 0 300.000000 300.000000' preserveAspectRatio='xMidYMid meet'><g transform='translate(0.000000,300.000000) scale(0.100000,-0.100000)' fill='#3F0607' stroke='none'><path class='node' id='node1' d='M1255 2979 c-214 -37 -373 -98 -560 -212 -105 -64 -246 -187 -333 -291 -457 -540 -483 -1307 -65 -1871 453 -611 1297 -784 1958 -402 156 91 335 250 448 399 31 42 57 80 57 84 0 4 6 15 14 23 30 34 105 191 140 293 124 359 113 724 -31 1078 -155 380 -487 695 -874 831 -246 86 -514 110 -754 68z m464 -544 c153 -37 268 -120 323 -233 31 -62 33 -73 33 -172 0 -82 -4 -115 -19 -150 -49 -111 -167 -242 -326 -359 -179 -132 -213 -178 -227 -302 l-8 -74 -55 0 -55 0 2 107 c3 151 25 219 118 363 114 178 161 315 151 445 -9 133 -48 204 -134 246 -47 24 -61 26 -135 22 -63 -3 -92 -10 -119 -26 -55 -34 -53 -51 12 -120 68 -72 85 -113 77 -190 -11 -108 -86 -165 -215 -164 -64 1 -82 5 -121 29 -134 83 -137 294 -8 427 84 85 184 138 312 162 88 17 306 11 394 -11z m-160 -1453 c25 -15 61 -49 80 -76 33 -46 36 -55 36 -125 0 -66 -4 -82 -27 -117 -108 -167 -308 -166 -417 1 -22 34 -26 51 -26 115 1 79 11 104 64 163 72 79 197 96 290 39z'></path></g><g transform='translate(0.000000,300.000000) scale(0.100000,-0.100000)' fill='#FFFFFF' stroke='none'><path class='node' id='node4' d='M1325 2446 c-128 -24 -228 -77 -312 -162 -129 -133 -126 -344 8 -427 39 -24 57 -28 121 -29 129 -1 204 56 215 164 8 77 -9 118 -77 190 -65 69 -67 86 -12 120 27 16 56 23 119 26 74 4 88 2 135 -22 86 -42 125 -113 134 -246 10 -130 -37 -267 -151 -445 -93 -144 -115 -212 -118 -363 l-2 -107 55 0 55 0 8 74 c14 124 48 170 227 302 159 117 277 248 326 359 15 35 19 68 19 150 0 99 -2 110 -33 172 -55 113 -170 196 -323 233 -88 22 -306 28 -394 11z'></path><path class='node' id='node7' d='M1385 1011 c-67 -17 -116 -56 -160 -126 -14 -22 -19 -49 -20 -105 0 -64 4 -81 26 -115 109 -167 309 -168 417 -1 23 35 27 51 27 117 0 70 -3 79 -36 125 -61 85 -165 128 -254 105z'></path></g></svg>") 50% 50% repeat transparent;
}
Please find the inline SVG in the CSS. This doesn't show anything in the background. not getting any issue as well. Please let me know if this is the right way of creating the background ? please note I am using Firefox. Same works in Chrome.
Firefox doesn't like the # in your data URL. Replace all the hashes with %23.
body {
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30.000000pt' height='30.000000pt' viewBox='0 0 300.000000 300.000000' preserveAspectRatio='xMidYMid meet'><g transform='translate(0.000000,300.000000) scale(0.100000,-0.100000)' fill='%233F0607' stroke='none'><path class='node' id='node1' d='M1255 2979 c-214 -37 -373 -98 -560 -212 -105 -64 -246 -187 -333 -291 -457 -540 -483 -1307 -65 -1871 453 -611 1297 -784 1958 -402 156 91 335 250 448 399 31 42 57 80 57 84 0 4 6 15 14 23 30 34 105 191 140 293 124 359 113 724 -31 1078 -155 380 -487 695 -874 831 -246 86 -514 110 -754 68z m464 -544 c153 -37 268 -120 323 -233 31 -62 33 -73 33 -172 0 -82 -4 -115 -19 -150 -49 -111 -167 -242 -326 -359 -179 -132 -213 -178 -227 -302 l-8 -74 -55 0 -55 0 2 107 c3 151 25 219 118 363 114 178 161 315 151 445 -9 133 -48 204 -134 246 -47 24 -61 26 -135 22 -63 -3 -92 -10 -119 -26 -55 -34 -53 -51 12 -120 68 -72 85 -113 77 -190 -11 -108 -86 -165 -215 -164 -64 1 -82 5 -121 29 -134 83 -137 294 -8 427 84 85 184 138 312 162 88 17 306 11 394 -11z m-160 -1453 c25 -15 61 -49 80 -76 33 -46 36 -55 36 -125 0 -66 -4 -82 -27 -117 -108 -167 -308 -166 -417 1 -22 34 -26 51 -26 115 1 79 11 104 64 163 72 79 197 96 290 39z'></path></g><g transform='translate(0.000000,300.000000) scale(0.100000,-0.100000)' fill='%23FFFFFF' stroke='none'><path class='node' id='node4' d='M1325 2446 c-128 -24 -228 -77 -312 -162 -129 -133 -126 -344 8 -427 39 -24 57 -28 121 -29 129 -1 204 56 215 164 8 77 -9 118 -77 190 -65 69 -67 86 -12 120 27 16 56 23 119 26 74 4 88 2 135 -22 86 -42 125 -113 134 -246 10 -130 -37 -267 -151 -445 -93 -144 -115 -212 -118 -363 l-2 -107 55 0 55 0 8 74 c14 124 48 170 227 302 159 117 277 248 326 359 15 35 19 68 19 150 0 99 -2 110 -33 172 -55 113 -170 196 -323 233 -88 22 -306 28 -394 11z'></path><path class='node' id='node7' d='M1385 1011 c-67 -17 -116 -56 -160 -126 -14 -22 -19 -49 -20 -105 0 -64 4 -81 26 -115 109 -167 309 -168 417 -1 23 35 27 51 27 117 0 70 -3 79 -36 125 -61 85 -165 128 -254 105z'></path></g></svg>") 50% 50% repeat transparent;
}
When you use background-image reference the svg as a file with a a path.
background-image: url(http://www.domain.com/path/img.svg);
So put all of that code that makes the svg into a text file, then change the extension from .txt to .svg
If you want to use it inline convert your svg with this tool: http://www.mobilefish.com/services/base64/base64.php
.imgSVG {
background: url("data:image/svg+xml;base64,[data]");
}
[data] portion is where you place whatever you get from the online tool.
SVG: https://css-tricks.com/using-svg/
URI: https://css-tricks.com/data-uris/
Related
This question already has answers here:
img src SVG changing the styles with CSS
(26 answers)
Closed 11 months ago.
I have this static existing svg that I have difficulties changing the color.
<img class="icon-shop" src="#/assets/icon-shop.svg"/>
<style>
.icon-shop {
width: 32px;
fill: orange;
stroke: orange;
}
</style>
I've found a solution using filter attribute but it shouldn't be this complicated.
filter: invert(35%) sepia(36%) saturate(7009%) hue-rotate(2deg)
brightness(104%) contrast(88%);
Sample is this if you change the fill="YOUR COLOR" that should change. You can view any svg on any text editor and change from there.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="300.000000pt" height="300.000000pt" viewBox="0 0 300.000000 300.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.10, written by Peter Selinger 2001-2011
</metadata>
<g transform="translate(0.000000,300.000000) scale(0.100000,-0.100000)"
fill="red" stroke="none">
<path d="M212 2613 c-128 -45 -197 -230 -142 -376 26 -70 122 -200 188 -255
39 -33 219 -160 962 -678 41 -28 104 -67 140 -85 58 -30 74 -34 145 -34 74 0
85 3 150 39 39 21 165 104 280 185 116 81 341 239 502 350 217 151 310 221
361 275 108 114 152 208 153 328 1 119 -63 215 -171 253 -37 13 -209 15 -1284
14 -1087 0 -1246 -2 -1284 -16z"/>
<path d="M50 1228 c0 -745 -2 -723 72 -798 22 -23 58 -50 81 -61 40 -18 87
-19 1297 -19 l1255 0 50 24 c55 25 105 76 132 134 16 34 18 95 21 705 2 367 0
667 -3 667 -3 0 -34 -24 -69 -54 -36 -30 -106 -83 -158 -117 -160 -107 -596
-411 -753 -523 -304 -219 -447 -257 -656 -175 -88 36 -129 62 -546 355 -142
99 -337 234 -433 300 -96 65 -200 143 -232 173 l-58 53 0 -664z"/>
</g>
</svg>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Create a sequence of numbers from -100 to 100 at the interval of 2,5,10,25.
How to do this in R in less lines of code.
I hope mapply can help you
> mapply(seq, -100, 100, c(2, 5, 10, 25))
[[1]]
[1] -100 -98 -96 -94 -92 -90 -88 -86 -84 -82 -80 -78 -76 -74 -72
[16] -70 -68 -66 -64 -62 -60 -58 -56 -54 -52 -50 -48 -46 -44 -42
[31] -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12
[46] -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18
[61] 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
[76] 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78
[91] 80 82 84 86 88 90 92 94 96 98 100
[[2]]
[1] -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30
[16] -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45
[31] 50 55 60 65 70 75 80 85 90 95 100
[[3]]
[1] -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40
[16] 50 60 70 80 90 100
[[4]]
[1] -100 -75 -50 -25 0 25 50 75 100
Or you can use Vectorize
> Vectorize(function(s) seq(-100, 100, s))(c(2, 5, 10, 25))
[[1]]
[1] -100 -98 -96 -94 -92 -90 -88 -86 -84 -82 -80 -78 -76 -74 -72
[16] -70 -68 -66 -64 -62 -60 -58 -56 -54 -52 -50 -48 -46 -44 -42
[31] -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12
[46] -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18
[61] 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
[76] 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78
[91] 80 82 84 86 88 90 92 94 96 98 100
[[2]]
[1] -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30
[16] -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45
[31] 50 55 60 65 70 75 80 85 90 95 100
[[3]]
[1] -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40
[16] 50 60 70 80 90 100
[[4]]
[1] -100 -75 -50 -25 0 25 50 75 100
I have this dataframe
time power hr fr VE VO2 VCO2 id
1 1462.0104166666667 25 90 24 20 632 549 LM01-PRD-S1
2 1462.0194444444444 25 92 23 21 679 597 LM01-PRD-S1
3 1462.0305555555556 25 93 22 21 675 607 LM01-PRD-S1
4 1462.0416666666667 25 93 20 19 680 577 LM01-PRD-S1
5 1462.0520833333333 40 96 20 22 745 660 LM01-PRD-S1
6 1462.0618055555556 40 98 21 22 764 675 LM01-PRD-S1
7 1462.0722222222223 40 100 21 22 789 703 LM01-PRD-S1
8 1462.0826388888888 40 100 20 23 805 734 LM01-PRD-S1
9 1462.09375 55 105 22 26 911 843 LM01-PRD-S1
10 1462.1041666666667 55 105 20 25 881 831 LM01-PRD-S1
11 1462.1131944444444 55 109 19 25 895 847 LM01-PRD-S1
12 1462.1229166666667 55 112 21 25 908 868 LM01-PRD-S1
13 1462.1347222222223 70 120 21 28 981 947 LM01-PRD-S1
14 1462.1451388888888 70 120 21 29 1044 1021 LM01-PRD-S1
15 1462.1548611111111 70 122 22 27 1066 1031 LM01-PRD-S1
16 1462.1652777777779 70 127 19 30 1136 1122 LM01-PRD-S1
17 1462.1770833333333 85 130 20 32 1181 1218 LM01-PRD-S1
18 1462.1868055555556 85 141 21 32 1194 1216 LM01-PRD-S1
19 1462.1958333333334 85 139 22 34 1231 1295 LM01-PRD-S1
20 1462.2069444444444 85 139 19 32 1193 1268 LM01-PRD-S1
21 1462.2166666666667 100 139 21 31 1192 1274 LM01-PRD-S1
22 1462.2291666666667 100 146 21 38 1363 1460 LM01-PRD-S1
23 1462.2395833333333 100 150 28 50 1551 1801 LM01-PRD-S1
24 1462.2479166666667 100 148 30 51 1499 1810 LM01-PRD-S1
25 1462.2597222222223 115 150 30 55 1564 1883 LM01-PRD-S1
26 1462.2708333333333 115 153 31 56 1544 1892 LM01-PRD-S1
27 1462.2805555555556 115 157 33 59 1545 2012 LM01-PRD-S1
28 1462.2881944444443 115 157 34 62 1647 2091 LM01-PRD-S1
29 NA NA NA RÈcupÈ ration NA NA LM01-PRD-S1
30 1462.0027777777777 65 157 39 61 1466 1940 LM01-PRD-S1
31 1462.0131944444445 20 153 32 58 1518 1939 LM01-PRD-S1
32 1462.0236111111112 20 148 28 50 1422 1748 LM01-PRD-S1
33 1462.0333333333333 20 144 26 46 1222 1555 LM01-PRD-S1
34 1462.0430555555556 20 141 22 37 963 1209 LM01-PRD-S1
35 1462.0541666666666 20 133 22 42 1165 1464 LM01-PRD-S1
36 1462.0645833333333 20 133 24 47 1021 1384 LM01-PRD-S1
37 1462.0743055555556 20 130 22 40 914 1228 LM01-PRD-S1
38 1462.0854166666666 20 130 23 38 847 1128 LM01-PRD-S1
39 1462.0944444444444 20 120 18 32 755 998 LM01-PRD-S1
40 1462.1069444444445 0 117 17 29 674 904 LM01-PRD-S1
41 1462.1173611111112 0 115 20 27 587 805 LM01-PRD-S1
42 1462.1277777777777 0 113 20 28 536 803 LM01-PRD-S1
43 1462.1368055555556 0 112 18 26 489 744 LM01-PRD-S1
44 1462.1479166666666 0 110 18 25 457 703 LM01-PRD-S1
45 1462.1590277777777 0 103 19 23 419 633 LM01-PRD-S1
46 1462.16875 0 103 17 24 479 672 LM01-PRD-S1
47 1462.1791666666666 0 103 19 21 423 560 LM01-PRD-S1
48 1462.1902777777777 0 100 19 22 459 609 LM01-PRD-S1
49 1462.1993055555556 0 101 18 22 440 599 LM01-PRD-S1
50 1462.004861111111 0 98 18 22 410 572 LM01-PRD-S1
51 1.0416666666666666E-2 35 102 16 18 659 576 LB02-PRD-S1
52 1.9444444444444445E-2 35 101 17 19 729 613 LB02-PRD-S1
53 3.0555555555555555E-2 35 105 15 28 977 851 LB02-PRD-S1
54 4.0972222222222222E-2 35 96 16 28 886 852 LB02-PRD-S1
55 4.9999999999999996E-2 50 90 16 16 593 504 LB02-PRD-S1
56 6.1111111111111116E-2 50 106 18 17 737 552 LB02-PRD-S1
57 7.2222222222222229E-2 50 108 19 23 1053 775 LB02-PRD-S1
58 8.2638888888888887E-2 50 117 17 30 1236 1008 LB02-PRD-S1
59 9.2361111111111116E-2 65 113 18 29 1181 983 LB02-PRD-S1
60 0.10347222222222223 65 114 15 31 1167 1016 LB02-PRD-S1
61 0.11388888888888889 65 118 16 31 1167 1052 LB02-PRD-S1
62 0.12430555555555556 65 114 17 28 1104 967 LB02-PRD-S1
63 0.13402777777777777 80 120 17 35 1318 1172 LB02-PRD-S1
64 0.1451388888888889 80 117 16 32 1236 1153 LB02-PRD-S1
65 0.15486111111111112 80 122 17 31 1168 1094 LB02-PRD-S1
66 0.16458333333333333 80 122 17 34 1312 1205 LB02-PRD-S1
67 0.1763888888888889 95 126 18 37 1311 1274 LB02-PRD-S1
68 0.18611111111111112 95 129 18 35 1248 1201 LB02-PRD-S1
69 0.19722222222222222 95 131 15 33 1275 1196 LB02-PRD-S1
70 0.20625000000000002 95 134 18 39 1444 1381 LB02-PRD-S1
71 0.21736111111111112 110 134 19 43 1539 1472 LB02-PRD-S1
72 0.22847222222222222 110 136 19 41 1417 1406 LB02-PRD-S1
73 0.2388888888888889 110 137 20 43 1496 1437 LB02-PRD-S1
74 0.25 110 139 20 44 1561 1539 LB02-PRD-S1
75 0.25972222222222224 125 142 21 46 1561 1560 LB02-PRD-S1
76 0.26944444444444443 125 146 21 46 1535 1552 LB02-PRD-S1
77 0.28055555555555556 125 148 23 51 1698 1703 LB02-PRD-S1
78 0.29166666666666669 125 150 23 53 1725 1776 LB02-PRD-S1
79 0.30069444444444443 140 151 22 52 1726 1760 LB02-PRD-S1
80 0.31180555555555556 140 151 23 53 1713 1763 LB02-PRD-S1
81 0.32222222222222224 140 153 25 55 1807 1836 LB02-PRD-S1
82 0.33263888888888887 140 155 26 58 1897 1941 LB02-PRD-S1
83 0.34375 155 153 26 59 1929 1963 LB02-PRD-S1
84 0.35347222222222219 155 157 26 57 1843 1908 LB02-PRD-S1
85 0.36388888888888887 155 160 28 65 1942 2065 LB02-PRD-S1
86 0.375 155 164 26 64 2011 2131 LB02-PRD-S1
87 0.38472222222222219 170 166 26 65 2048 2178 LB02-PRD-S1
88 0.39583333333333331 170 166 26 64 2069 2171 LB02-PRD-S1
89 0.40625 170 169 25 64 2165 2269 LB02-PRD-S1
90 0.41666666666666669 170 169 28 76 2328 2539 LB02-PRD-S1
91 0.42638888888888887 185 169 30 76 2189 2449 LB02-PRD-S1
92 0.4368055555555555 185 171 29 73 2225 2411 LB02-PRD-S1
93 0.44722222222222219 185 171 29 68 2170 2292 LB02-PRD-S1
94 0.45763888888888887 185 171 31 82 2458 2712 LB02-PRD-S1
95 0.4680555555555555 200 171 33 89 2443 2780 LB02-PRD-S1
96 0.47847222222222219 200 173 33 87 2465 2784 LB02-PRD-S1
97 0.48888888888888887 200 176 32 88 2536 2853 LB02-PRD-S1
98 0.5 200 176 34 93 2571 2899 LB02-PRD-S1
99 0.51041666666666663 215 176 36 98 2529 2924 LB02-PRD-S1
100 0.52083333333333337 215 179 36 105 2602 3087 LB02-PRD-S1
101 0.53125 215 179 39 111 2795 3282 LB02-PRD-S1
102 0.54097222222222219 215 181 40 118 2679 3240 LB02-PRD-S1
103 0.55208333333333337 230 179 40 113 2649 3160 LB02-PRD-S1
104 0.56180555555555556 230 179 41 111 2601 3055 LB02-PRD-S1
105 0.57291666666666663 230 176 42 116 2639 3129 LB02-PRD-S1
106 0.58263888888888882 230 181 43 126 2683 3277 LB02-PRD-S1
107 0.59375 245 181 47 123 2597 3160 LB02-PRD-S1
108 0.60416666666666663 245 181 48 128 2482 3122 LB02-PRD-S1
109 NA NA NA RÈcupÈ ration NA NA LB02-PRD-S1
110 9.7222222222222224E-3 20 179 42 108 2320 2830 LB02-PRD-S1
111 2.013888888888889E-2 20 173 40 106 2134 2594 LB02-PRD-S1
112 3.125E-2 20 171 37 103 1869 2531 LB02-PRD-S1
113 4.0972222222222222E-2 20 166 38 97 1438 2207 LB02-PRD-S1
114 5.1388888888888894E-2 20 164 36 88 1192 1918 LB02-PRD-S1
115 6.1805555555555558E-2 20 155 37 81 1121 1746 LB02-PRD-S1
116 7.0833333333333331E-2 20 142 32 71 1072 1585 LB02-PRD-S1
117 8.1944444444444445E-2 20 151 26 56 961 1345 LB02-PRD-S1
118 9.2361111111111116E-2 20 148 28 58 996 1367 LB02-PRD-S1
119 0.10277777777777779 20 144 24 49 858 1189 LB02-PRD-S1
120 0.11319444444444444 20 141 25 49 722 1053 LB02-PRD-S1
121 0.125 0 136 25 42 611 895 LB02-PRD-S1
122 0.13472222222222222 0 131 26 42 642 893 LB02-PRD-S1
123 0.1451388888888889 0 129 28 44 612 874 LB02-PRD-S1
124 0.15555555555555556 0 126 24 36 544 728 LB02-PRD-S1
125 0.16527777777777777 0 127 26 40 658 840 LB02-PRD-S1
126 0.1763888888888889 0 130 23 31 511 665 LB02-PRD-S1
127 0.18611111111111112 0 126 24 39 646 815 LB02-PRD-S1
128 0.19652777777777777 0 120 25 38 527 716 LB02-PRD-S1
129 0.20694444444444446 0 120 24 36 509 684 LB02-PRD-S1
130 1462.0104166666667 25 101 20 18 712 584 GC03-PRD-S1
131 1462.0208333333333 25 99 20 17 673 551 GC03-PRD-S1
132 1462.03125 25 97 20 17 686 559 GC03-PRD-S1
133 1462.0402777777779 25 96 20 16 639 524 GC03-PRD-S1
134 1462.0506944444444 40 99 19 16 647 518 GC03-PRD-S1
135 1462.0604166666667 40 105 19 16 669 543 GC03-PRD-S1
136 1462.0729166666667 40 107 21 18 723 598 GC03-PRD-S1
137 1462.0826388888888 40 107 25 19 746 605 GC03-PRD-S1
138 1462.0916666666667 55 109 23 20 775 645 GC03-PRD-S1
139 1462.1020833333334 55 111 20 20 780 671 GC03-PRD-S1
140 1462.1118055555555 55 116 21 21 811 710 GC03-PRD-S1
141 1462.1243055555556 55 113 17 22 858 765 GC03-PRD-S1
142 1462.1340277777779 70 117 21 23 900 789 GC03-PRD-S1
143 1462.1458333333333 70 117 20 23 953 843 GC03-PRD-S1
144 1462.15625 70 120 20 25 980 882 GC03-PRD-S1
145 1462.1652777777779 70 122 22 26 1000 916 GC03-PRD-S1
146 1462.1763888888888 85 122 23 27 1049 961 GC03-PRD-S1
147 1462.1868055555556 85 126 23 28 1072 992 GC03-PRD-S1
148 1462.1965277777779 85 131 22 29 1110 1056 GC03-PRD-S1
149 1462.2076388888888 85 130 22 30 1066 1047 GC03-PRD-S1
150 1462.2173611111111 100 129 21 28 1166 1057 GC03-PRD-S1
151 1462.2284722222223 100 137 27 34 1346 1247 GC03-PRD-S1
152 1462.2395833333333 100 137 22 34 1272 1261 GC03-PRD-S1
153 1462.25 100 136 20 33 1222 1235 GC03-PRD-S1
154 1462.2590277777779 115 139 23 36 1321 1321 GC03-PRD-S1
155 1462.2701388888888 115 142 23 37 1340 1377 GC03-PRD-S1
156 1462.2798611111111 115 144 24 38 1362 1418 GC03-PRD-S1
157 1462.2909722222223 115 150 27 44 1470 1579 GC03-PRD-S1
158 1462.3013888888888 130 151 27 45 1466 1618 GC03-PRD-S1
159 1462.3125 130 153 31 54 1686 1875 GC03-PRD-S1
160 1462.3222222222223 130 155 33 59 1679 1998 GC03-PRD-S1
161 1462.3326388888888 130 157 33 59 1676 2021 GC03-PRD-S1
162 1462.3423611111111 145 157 33 61 1700 2041 GC03-PRD-S1
163 1462.3534722222223 145 160 35 64 1764 2120 GC03-PRD-S1
164 1462.3638888888888 145 160 36 67 1765 2182 GC03-PRD-S1
165 1462.3743055555556 145 162 40 71 1762 2208 GC03-PRD-S1
166 1462.0006944444444 145 162 39 69 1754 2208 GC03-PRD-S1
167 NA NA NA RÈcupÈ ration NA NA GC03-PRD-S1
168 1462.0097222222223 20 155 38 68 1687 2124 GC03-PRD-S1
169 1462.0194444444444 20 148 39 67 1576 1996 GC03-PRD-S1
170 1462.0298611111111 20 142 35 62 1390 1842 GC03-PRD-S1
171 1462.0409722222223 20 136 35 58 1189 1632 GC03-PRD-S1
172 1462.05 20 127 26 46 991 1337 GC03-PRD-S1
173 1462.0604166666667 20 117 21 26 776 896 GC03-PRD-S1
174 1462.0715277777779 20 115 22 31 855 1012 GC03-PRD-S1
175 1462.0819444444444 20 111 23 30 783 950 GC03-PRD-S1
176 1462.0930555555556 20 109 23 30 756 939 GC03-PRD-S1
177 1462.1020833333334 20 100 23 28 702 870 GC03-PRD-S1
178 1462.1131944444444 20 104 23 29 685 853 GC03-PRD-S1
179 1462.1236111111111 20 90 19 20 471 594 GC03-PRD-S1
180 1462.1340277777779 0 96 20 20 494 607 GC03-PRD-S1
181 1462.1444444444444 0 94 20 19 439 559 GC03-PRD-S1
182 1462.1548611111111 0 93 20 19 425 561 GC03-PRD-S1
183 1462.1638888888888 0 90 19 17 357 480 GC03-PRD-S1
184 1462.175 0 91 18 16 345 443 GC03-PRD-S1
185 1462.1854166666667 0 96 21 18 370 480 GC03-PRD-S1
186 1462.1958333333334 0 92 20 16 324 420 GC03-PRD-S1
187 1462.2076388888888 0 92 20 16 324 414 GC03-PRD-S1
188 1462.0083333333334 0 93 20 15 309 391 GC03-PRD-S1
189 1462.0104166666667 60 127 27 40 1267 1274 GT04-PRD-S1
190 1462.0201388888888 60 131 29 40 1264 1274 GT04-PRD-S1
191 1462.0305555555556 60 133 30 40 1281 1298 GT04-PRD-S1
192 1462.0402777777779 60 134 29 42 1304 1360 GT04-PRD-S1
193 1462.0513888888888 80 134 28 40 1274 1324 GT04-PRD-S1
194 1462.0625 80 137 28 40 1337 1335 GT04-PRD-S1
195 1462.0729166666667 80 144 29 45 1485 1501 GT04-PRD-S1
196 1462.0833333333333 80 144 30 50 1573 1630 GT04-PRD-S1
197 1462.0930555555556 100 148 30 47 1380 1478 GT04-PRD-S1
198 1462.1034722222223 100 150 30 49 1520 1576 GT04-PRD-S1
199 1462.1145833333333 100 153 31 50 1553 1589 GT04-PRD-S1
200 1462.1243055555556 100 151 31 55 1735 1818 GT04-PRD-S1
201 1462.1340277777779 120 153 32 65 1905 2146 GT04-PRD-S1
202 1462.1444444444444 120 151 32 62 1748 2026 GT04-PRD-S1
203 1462.1555555555556 120 160 31 61 1799 2041 GT04-PRD-S1
204 1462.1652777777779 120 160 30 64 1810 2105 GT04-PRD-S1
205 1462.1756944444444 140 164 33 73 1895 2314 GT04-PRD-S1
206 1462.1861111111111 140 162 33 72 1966 2345 GT04-PRD-S1
207 1462.1972222222223 140 166 36 79 2021 2470 GT04-PRD-S1
208 1462.2083333333333 140 166 35 76 2022 2450 GT04-PRD-S1
209 1462.2180555555556 160 164 37 78 2115 2491 GT04-PRD-S1
210 1462.2284722222223 160 169 40 82 2147 2583 GT04-PRD-S1
211 1462.2388888888888 160 169 38 83 2190 2647 GT04-PRD-S1
212 1462.2493055555556 160 173 38 85 2202 2713 GT04-PRD-S1
213 1462.2604166666667 180 171 38 88 2332 2837 GT04-PRD-S1
214 1462.2701388888888 180 171 41 95 2321 2937 GT04-PRD-S1
215 1462.28125 180 176 39 94 2358 2994 GT04-PRD-S1
216 1462.2909722222223 180 176 42 104 2339 3086 GT04-PRD-S1
217 1462.2979166666667 200 176 44 105 2444 3186 GT04-PRD-S1
218 NA NA NA RÈcupÈ ration NA NA GT04-PRD-S1
219 1462.0034722222222 125 179 42 97 2304 2957 GT04-PRD-S1
220 1462.0131944444445 30 171 38 92 2266 2900 GT04-PRD-S1
221 1462.0236111111112 30 166 36 93 2136 2851 GT04-PRD-S1
222 1462.0347222222222 30 166 35 91 1829 2619 GT04-PRD-S1
223 1462.0444444444445 30 162 34 83 1576 2306 GT04-PRD-S1
224 1462.0548611111112 30 160 31 65 1411 1904 GT04-PRD-S1
225 1462.0652777777777 30 155 36 78 1439 2013 GT04-PRD-S1
226 1462.0763888888889 30 153 34 69 1337 1832 GT04-PRD-S1
227 1462.0861111111112 30 153 34 66 1283 1716 GT04-PRD-S1
228 1462.0965277777777 30 144 28 49 1012 1303 GT04-PRD-S1
229 1462.1069444444445 30 134 25 41 897 1147 GT04-PRD-S1
230 1462.1180555555557 0 130 25 40 756 1051 GT04-PRD-S1
231 1462.1284722222222 0 126 20 28 500 741 GT04-PRD-S1
232 1462.1381944444445 0 123 23 27 533 712 GT04-PRD-S1
233 1462.1486111111112 0 123 23 29 548 737 GT04-PRD-S1
234 1462.1590277777777 0 117 24 24 415 560 GT04-PRD-S1
235 1462.16875 0 114 21 27 610 728 GT04-PRD-S1
236 1462.1798611111112 0 111 19 23 508 612 GT04-PRD-S1
237 1462.1902777777777 0 113 21 26 548 666 GT04-PRD-S1
238 1462.2006944444445 0 113 23 27 552 683 GT04-PRD-S1
239 1462.0020833333333 0 114 22 28 547 702 GT04-PRD-S1
I would like to remove all rows after words "ration" in the column VE BUT only for each id.
Meaning that I would like to remove lines 29 to 50, 109 to 129, 167 to 188, and from 218 to 239.
The word "ration" is repeated several times, and please take into account that I have several ID (I can not include it in my question because it is too long).
I tried to create at the end of each id but it did not work.
Thank you for your help!
With dplyr:
data %>%
group_by(id) %>%
filter(cumsum(VE == "ration") == 0)
Assuming for all the id you'll have a row with "ration", you can use dplyr like
library(dplyr)
df %>% group_by(id) %>% slice(1:(which.max(VE == "ration") -1))
I am new to ggplot2. In fact, I only discovered it last week and I haven't quite figured out yet how to use aesthetics and scales etc. There is probably a very easy solution to my problem but I couldn't find a satisfying answer online.
Sorry for the size of the message, but all the data used is in the following script:
dados
Fres Vc Lu
1 466 30 10
2 416 30 10
3 465 30 10
4 416 30 10
5 464 30 10
6 416 30 10
7 476 30 10
8 412 30 10
9 468 30 10
10 410 30 10
11 470 30 10
12 407 30 10
13 468 30 10
14 412 30 10
15 469 30 10
16 414 30 10
17 469 30 10
18 412 30 10
19 467 30 10
20 409 30 10
21 469 30 10
22 415 30 10
23 471 30 10
24 420 30 10
25 469 30 10
26 416 30 10
27 464 30 10
28 409 30 10
29 465 30 10
30 412 30 10
31 464 30 10
32 409 30 10
33 466 30 10
34 417 30 10
35 466 30 10
36 417 30 10
37 464 30 10
38 414 30 10
39 466 30 10
40 415 30 10
41 585 30 94
42 234 30 94
43 589 30 94
44 231 30 94
45 585 30 94
46 223 30 94
47 586 30 94
48 223 30 94
49 572 30 94
50 233 30 94
51 585 30 94
52 233 30 94
53 589 30 94
54 234 30 94
55 598 30 94
56 237 30 94
57 605 30 94
58 237 30 94
59 586 30 94
60 233 30 94
61 588 30 94
62 227 30 94
63 585 30 94
64 230 30 94
65 586 30 94
66 230 30 94
67 591 30 94
68 237 30 94
69 586 30 94
70 234 30 94
71 592 30 94
72 237 30 94
73 595 30 94
74 236 30 94
75 600 30 94
76 227 30 94
77 592 30 94
78 237 30 94
79 592 30 94
80 240 30 94
81 468 30 10
82 408 30 10
83 471 30 10
84 405 30 10
85 475 30 10
86 403 30 10
87 470 30 10
88 409 30 10
89 478 30 10
90 405 30 10
91 474 30 10
92 403 30 10
93 472 30 10
94 402 30 10
95 478 30 10
96 408 30 10
97 477 30 10
98 406 30 10
99 473 30 10
100 406 30 10
101 474 30 10
102 406 30 10
103 477 30 10
104 411 30 10
105 480 30 10
106 413 30 10
107 479 30 10
108 408 30 10
109 476 30 10
110 406 30 10
111 476 30 10
112 404 30 10
113 472 30 10
114 407 30 10
115 474 30 10
116 411 30 10
117 473 30 10
118 415 30 10
119 479 30 10
120 409 30 10
121 578 30 94
122 370 30 94
123 570 30 94
124 378 30 94
125 575 30 94
126 367 30 94
127 579 30 94
128 371 30 94
129 576 30 94
130 362 30 94
131 579 30 94
132 372 30 94
133 588 30 94
134 375 30 94
135 586 30 94
136 372 30 94
137 589 30 94
138 378 30 94
139 587 30 94
140 375 30 94
141 578 30 94
142 368 30 94
143 575 30 94
144 375 30 94
145 574 30 94
146 376 30 94
147 575 30 94
148 367 30 94
149 580 30 94
150 382 30 94
151 583 30 94
152 368 30 94
153 591 30 94
154 386 30 94
155 595 30 94
156 379 30 94
157 593 30 94
158 384 30 94
159 607 30 94
160 399 30 94
161 760 30 122
162 625 30 122
163 746 30 122
164 612 30 122
165 762 30 122
166 625 30 122
167 783 30 122
168 637 30 122
169 778 30 122
170 640 30 122
171 778 30 122
172 638 30 122
173 791 30 122
174 638 30 122
175 782 30 122
176 635 30 122
177 792 30 122
178 640 30 122
179 783 30 122
180 637 30 122
181 774 30 122
182 622 30 122
183 777 30 122
184 618 30 122
185 777 30 122
186 622 30 122
187 765 30 122
188 623 30 122
189 769 30 122
190 625 30 122
191 775 30 122
192 622 30 122
193 777 30 122
194 628 30 122
195 769 30 122
196 620 30 122
197 778 30 122
198 623 30 122
199 788 30 122
200 634 30 122
201 457 40 38
202 416 40 38
203 460 40 38
204 438 40 38
205 465 40 38
206 441 40 38
207 467 40 38
208 442 40 38
209 473 40 38
210 452 40 38
211 469 40 38
212 446 40 38
213 478 40 38
214 450 40 38
215 476 40 38
216 454 40 38
217 479 40 38
218 452 40 38
219 480 40 38
220 450 40 38
221 481 40 38
222 443 40 38
223 476 40 38
224 447 40 38
225 472 40 38
226 450 40 38
227 479 40 38
228 449 40 38
229 478 40 38
230 455 40 38
231 478 40 38
232 457 40 38
233 481 40 38
234 447 40 38
235 504 40 38
236 452 40 38
237 472 40 38
238 447 40 38
239 472 40 38
240 451 40 38
241 622 40 66
242 377 40 66
243 619 40 66
244 378 40 66
245 622 40 66
246 369 40 66
247 616 40 66
248 374 40 66
249 619 40 66
250 374 40 66
251 616 40 66
252 374 40 66
253 621 40 66
254 375 40 66
255 618 40 66
256 397 40 66
257 633 40 66
258 406 40 66
259 652 40 66
260 412 40 66
261 652 40 66
262 419 40 66
263 658 40 66
264 423 40 66
265 659 40 66
266 409 40 66
267 650 40 66
268 405 40 66
269 653 40 66
270 405 40 66
271 652 40 66
272 403 40 66
273 656 40 66
274 408 40 66
275 644 40 66
276 406 40 66
277 649 40 66
278 412 40 66
279 650 40 66
280 406 40 66
281 853 40 122
282 330 40 122
283 859 40 122
284 323 40 122
285 842 40 122
286 308 40 122
287 842 40 122
288 324 40 122
289 831 40 122
290 334 40 122
291 838 40 122
292 341 40 122
293 836 40 122
294 328 40 122
295 840 40 122
296 324 40 122
297 836 40 122
298 321 40 122
299 831 40 122
300 328 40 122
301 833 40 122
302 328 40 122
303 840 40 122
304 330 40 122
305 831 40 122
306 321 40 122
307 833 40 122
308 328 40 122
309 833 40 122
310 321 40 122
311 840 40 122
312 319 40 122
313 838 40 122
314 317 40 122
315 831 40 122
316 319 40 122
317 827 40 122
318 323 40 122
319 836 40 122
320 328 40 122
321 442 40 38
322 407 40 38
323 437 40 38
324 410 40 38
325 444 40 38
326 412 40 38
327 440 40 38
328 414 40 38
329 439 40 38
330 413 40 38
331 436 40 38
332 416 40 38
333 446 40 38
334 412 40 38
335 438 40 38
336 414 40 38
337 443 40 38
338 408 40 38
339 446 40 38
340 407 40 38
341 445 40 38
342 413 40 38
343 453 40 38
344 414 40 38
345 449 40 38
346 417 40 38
347 447 40 38
348 411 40 38
349 443 40 38
350 417 40 38
351 447 40 38
352 410 40 38
353 449 40 38
354 409 40 38
355 442 40 38
356 413 40 38
357 451 40 38
358 412 40 38
359 447 40 38
360 420 40 38
361 526 40 66
362 467 40 66
363 532 40 66
364 470 40 66
365 528 40 66
366 474 40 66
367 529 40 66
368 472 40 66
369 533 40 66
370 480 40 66
371 542 40 66
372 487 40 66
373 545 40 66
374 504 40 66
375 549 40 66
376 507 40 66
377 546 40 66
378 517 40 66
379 541 40 66
380 518 40 66
381 554 40 66
382 514 40 66
383 564 40 66
384 514 40 66
385 571 40 66
386 522 40 66
387 575 40 66
388 525 40 66
389 582 40 66
390 533 40 66
391 588 40 66
392 536 40 66
393 591 40 66
394 553 40 66
395 592 40 66
396 557 40 66
397 592 40 66
398 563 40 66
399 583 40 66
400 568 40 66
> dadosc <- summarySE(dados, measurevar="Fres", groupvars=c("Vc","Lu"))
> dadosc
Vc Lu N Fres sd se ci
1 30 10 80 440.6875 30.91540 3.456447 6.879885
2 30 94 80 445.0250 150.97028 16.878990 33.596789
3 30 122 40 701.7000 75.06688 11.869115 24.007552
4 40 38 80 444.6125 23.31973 2.607225 5.189552
5 40 66 80 526.7125 90.77824 10.149316 20.201707
6 40 122 40 581.1250 259.74092 41.068645 83.069175
> ggplot(dadosc, aes(x=Lu, y=Fres, colour=Vc)) +
+ geom_errorbar(aes(ymin=Fres-se, ymax=Fres+se), width=5) +
+ geom_point()
> pd <- position_dodge(0.1)
Up to here I got this graph, very close to my desired graph, except for the fact I´d like a legend with only two colors, one for Vc=30 and other for Vc=40.
![enter image description here][1]
Then I try the following script:
ggplot(dadosc, aes(x=Lu, y=Fres, ymax = max(Fres), colour=Vc, group=Vc)) +
+ geom_errorbar(aes(ymin=Fres-se, ymax=Fres+se), colour="black", width=.1, position=pd) +
+ geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
+ xlab("Machining lenght (mm)") +
+ ylab("Machining forces (N)") +
+ scale_colour_hue(name="Cutting Velocity",
+ breaks=c("30", "40"),
+ labels=c("Vc = 30 m/min", " Vc = 40 m/min "),
+ l=40) +
+ ggtitle("The Effect of Cutting Velocity on Machining Forces") +
+ expand_limits(y=0) +
+ scale_y_continuous(breaks=0:750*50) +
+ theme_bw() +
+ theme(legend.justification=c(1,0),
+ legend.position=c(1,0))
Error: Continuous value supplied to discrete scale
And I receive this message:
"Error: Continuous value supplied to discrete scale"!
Vc should be a factor if you want two values in the legend. You were getting that error because you were trying to scale Vc as discrete (breaks = c(30, 40)) when it was of type integer
ggplot(dadosc, aes(x=Lu, y=Fres, colour=factor(Vc))) +
...
I've got two dataframes that have same number of rows (22 rows) and different number of columns.
sim_10(22 rows, 15 columns):
2 0.577967 0.023869 0.021571 0.481754 0.61584 0 0 0 0 0 0.024057 0.014209 1 0.085784
8 0.0775 0.274113 2.7e-05 0.01215 0.009345 0 0 0 0 0 0.004092 0.00784 0 0
And how can I do it in easy way..
...
nm_10(22 rows, 8 columns)
11 0.926554 0.256966 0.859375 0 0.191011 0 0 0
2 0.858757 0.256966 0.21875 0 0.662921 0 0.845506 0.090909
..
the first column of two dataframes are same just in different order(names of cases). I need to find the matching row names in nm_10 and sm_10 and subtract every element of sm_10 in that row to the every element in the nm_10. example:
for '2' sm_nm_10:
2 (0.577967-0.858757=-0.28079) (0.577967-0.256966=) (0.577967-0.21875) ...(0.577967-0.090909=..)
(0.023869-0.858757=) (0.023869-0.256966=) (0.023869-0.21875) ...(0.023869-0.090909=..)
....
(0.085784-0.858757=) (0.085784-0.256966=) (0.085784-0.21875) ...(0.085784-0.090909=..)
and that for all data.
Check every row's first column, find matching row and do operation.
Is there any simple way to do it? I looked into sweep, apply but couldn't figure out how to use them. I keep getting errors referring to length etc. I decided to keep it simple and here is what I have :
s = numeric()
for (i in 1:nrow(sm_10))
{
for (jj in 1:nrow(nm_10))
{
for (j in 2:ncol(nm_10))
{
for (ii in 2:ncol(sm_10))
{
sm_10[i,]%in% nm_10[jj,]
s <- sm_10[,ii]-nm_10[,j]
}}}}
What is wrong here? Could anyone explain and suggest better?
UPDATE:
The end result I need is all rows 22 with the elements subtractions. that is 22 rows with (14*7 ) columns..
We can subset the larger dataset ("sim_10") by indexing the row names and column names of the subset dataset ("nm_10") and subtract the subset data (which has elements in corresponding row/column positions as "nm_10") from "nm_10".
sim_10[rownames(nm_10),colnames(nm_10)] - nm_10
data
set.seed(24)
sim_10 <- as.data.frame(matrix(sample(1:20, 22*15, replace=TRUE), ncol=15))
set.seed(42)
nm_10 <- as.data.frame(matrix(sample(1:40, 22*8, replace=TRUE), ncol=8))
set.seed(32)
colnames(nm_10) <- sample(colnames(sim_10), 8, replace=FALSE)
rownames(nm_10) <- sample(rownames(sim_10), 22, replace=FALSE)
I think the best solution here is to replicate the LHS by a sufficient multiplier such that it will then possess the desired output width, and then simply subtract the RHS from it. This will naturally be a vectorized subtraction and will cycle the RHS a sufficient number of times to fully cover the widened LHS. We must just take care to ensure that the pairing of elements is correct, which requires two things: (1) reorder the rows of the RHS such that the key values align with the LHS, and (2) replicate the LHS using the each parameter of rep(), rather than the times parameter:
df1 <- as.data.frame(cbind(sample(1:22),matrix(1:(22*14),22)));
df2 <- as.data.frame(cbind(sample(1:22),matrix(1:(22*7),22)));
df1;
## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15
## 1 22 1 23 45 67 89 111 133 155 177 199 221 243 265 287
## 2 20 2 24 46 68 90 112 134 156 178 200 222 244 266 288
## 3 13 3 25 47 69 91 113 135 157 179 201 223 245 267 289
## 4 12 4 26 48 70 92 114 136 158 180 202 224 246 268 290
## 5 16 5 27 49 71 93 115 137 159 181 203 225 247 269 291
## 6 7 6 28 50 72 94 116 138 160 182 204 226 248 270 292
## 7 1 7 29 51 73 95 117 139 161 183 205 227 249 271 293
## 8 2 8 30 52 74 96 118 140 162 184 206 228 250 272 294
## 9 9 9 31 53 75 97 119 141 163 185 207 229 251 273 295
## 10 14 10 32 54 76 98 120 142 164 186 208 230 252 274 296
## 11 4 11 33 55 77 99 121 143 165 187 209 231 253 275 297
## 12 21 12 34 56 78 100 122 144 166 188 210 232 254 276 298
## 13 15 13 35 57 79 101 123 145 167 189 211 233 255 277 299
## 14 10 14 36 58 80 102 124 146 168 190 212 234 256 278 300
## 15 8 15 37 59 81 103 125 147 169 191 213 235 257 279 301
## 16 6 16 38 60 82 104 126 148 170 192 214 236 258 280 302
## 17 19 17 39 61 83 105 127 149 171 193 215 237 259 281 303
## 18 3 18 40 62 84 106 128 150 172 194 216 238 260 282 304
## 19 5 19 41 63 85 107 129 151 173 195 217 239 261 283 305
## 20 18 20 42 64 86 108 130 152 174 196 218 240 262 284 306
## 21 17 21 43 65 87 109 131 153 175 197 219 241 263 285 307
## 22 11 22 44 66 88 110 132 154 176 198 220 242 264 286 308
df2;
## V1 V2 V3 V4 V5 V6 V7 V8
## 1 6 1 23 45 67 89 111 133
## 2 17 2 24 46 68 90 112 134
## 3 12 3 25 47 69 91 113 135
## 4 20 4 26 48 70 92 114 136
## 5 13 5 27 49 71 93 115 137
## 6 10 6 28 50 72 94 116 138
## 7 16 7 29 51 73 95 117 139
## 8 15 8 30 52 74 96 118 140
## 9 21 9 31 53 75 97 119 141
## 10 22 10 32 54 76 98 120 142
## 11 1 11 33 55 77 99 121 143
## 12 18 12 34 56 78 100 122 144
## 13 9 13 35 57 79 101 123 145
## 14 4 14 36 58 80 102 124 146
## 15 11 15 37 59 81 103 125 147
## 16 19 16 38 60 82 104 126 148
## 17 8 17 39 61 83 105 127 149
## 18 5 18 40 62 84 106 128 150
## 19 3 19 41 63 85 107 129 151
## 20 7 20 42 64 86 108 130 152
## 21 2 21 43 65 87 109 131 153
## 22 14 22 44 66 88 110 132 154
cbind(df1[,1],as.data.frame(rep(df1[,-1],each=ncol(df2)-1))-as.matrix(df2[match(df1[,1],df2[,1]),-1]));
## df1[, 1] V2 V2.1 V2.2 V2.3 V2.4 V2.5 V2.6 V3 V3.1 V3.2 V3.3 V3.4 V3.5 V3.6 V4 V4.1 V4.2 V4.3 V4.4 V4.5 V4.6 V5 V5.1 V5.2 V5.3 V5.4 V5.5 V5.6 V6 V6.1 V6.2 V6.3 V6.4 V6.5 V6.6 V7 V7.1 V7.2 V7.3 V7.4 V7.5 V7.6 V8 V8.1 V8.2 V8.3 V8.4 V8.5 V8.6 V9 V9.1 V9.2 V9.3 V9.4 V9.5 V9.6 V10 V10.1 V10.2 V10.3 V10.4 V10.5 V10.6 V11 V11.1 V11.2 V11.3 V11.4 V11.5 V11.6 V12 V12.1 V12.2 V12.3 V12.4 V12.5 V12.6 V13 V13.1 V13.2 V13.3 V13.4 V13.5 V13.6 V14 V14.1 V14.2 V14.3 V14.4 V14.5 V14.6 V15 V15.1 V15.2 V15.3 V15.4 V15.5 V15.6
## 1 22 -9 -31 -53 -75 -97 -119 -141 13 -9 -31 -53 -75 -97 -119 35 13 -9 -31 -53 -75 -97 57 35 13 -9 -31 -53 -75 79 57 35 13 -9 -31 -53 101 79 57 35 13 -9 -31 123 101 79 57 35 13 -9 145 123 101 79 57 35 13 167 145 123 101 79 57 35 189 167 145 123 101 79 57 211 189 167 145 123 101 79 233 211 189 167 145 123 101 255 233 211 189 167 145 123 277 255 233 211 189 167 145
## 2 20 -2 -24 -46 -68 -90 -112 -134 20 -2 -24 -46 -68 -90 -112 42 20 -2 -24 -46 -68 -90 64 42 20 -2 -24 -46 -68 86 64 42 20 -2 -24 -46 108 86 64 42 20 -2 -24 130 108 86 64 42 20 -2 152 130 108 86 64 42 20 174 152 130 108 86 64 42 196 174 152 130 108 86 64 218 196 174 152 130 108 86 240 218 196 174 152 130 108 262 240 218 196 174 152 130 284 262 240 218 196 174 152
## 3 13 -2 -24 -46 -68 -90 -112 -134 20 -2 -24 -46 -68 -90 -112 42 20 -2 -24 -46 -68 -90 64 42 20 -2 -24 -46 -68 86 64 42 20 -2 -24 -46 108 86 64 42 20 -2 -24 130 108 86 64 42 20 -2 152 130 108 86 64 42 20 174 152 130 108 86 64 42 196 174 152 130 108 86 64 218 196 174 152 130 108 86 240 218 196 174 152 130 108 262 240 218 196 174 152 130 284 262 240 218 196 174 152
## 4 12 1 -21 -43 -65 -87 -109 -131 23 1 -21 -43 -65 -87 -109 45 23 1 -21 -43 -65 -87 67 45 23 1 -21 -43 -65 89 67 45 23 1 -21 -43 111 89 67 45 23 1 -21 133 111 89 67 45 23 1 155 133 111 89 67 45 23 177 155 133 111 89 67 45 199 177 155 133 111 89 67 221 199 177 155 133 111 89 243 221 199 177 155 133 111 265 243 221 199 177 155 133 287 265 243 221 199 177 155
## 5 16 -2 -24 -46 -68 -90 -112 -134 20 -2 -24 -46 -68 -90 -112 42 20 -2 -24 -46 -68 -90 64 42 20 -2 -24 -46 -68 86 64 42 20 -2 -24 -46 108 86 64 42 20 -2 -24 130 108 86 64 42 20 -2 152 130 108 86 64 42 20 174 152 130 108 86 64 42 196 174 152 130 108 86 64 218 196 174 152 130 108 86 240 218 196 174 152 130 108 262 240 218 196 174 152 130 284 262 240 218 196 174 152
## 6 7 -14 -36 -58 -80 -102 -124 -146 8 -14 -36 -58 -80 -102 -124 30 8 -14 -36 -58 -80 -102 52 30 8 -14 -36 -58 -80 74 52 30 8 -14 -36 -58 96 74 52 30 8 -14 -36 118 96 74 52 30 8 -14 140 118 96 74 52 30 8 162 140 118 96 74 52 30 184 162 140 118 96 74 52 206 184 162 140 118 96 74 228 206 184 162 140 118 96 250 228 206 184 162 140 118 272 250 228 206 184 162 140
## 7 1 -4 -26 -48 -70 -92 -114 -136 18 -4 -26 -48 -70 -92 -114 40 18 -4 -26 -48 -70 -92 62 40 18 -4 -26 -48 -70 84 62 40 18 -4 -26 -48 106 84 62 40 18 -4 -26 128 106 84 62 40 18 -4 150 128 106 84 62 40 18 172 150 128 106 84 62 40 194 172 150 128 106 84 62 216 194 172 150 128 106 84 238 216 194 172 150 128 106 260 238 216 194 172 150 128 282 260 238 216 194 172 150
## 8 2 -13 -35 -57 -79 -101 -123 -145 9 -13 -35 -57 -79 -101 -123 31 9 -13 -35 -57 -79 -101 53 31 9 -13 -35 -57 -79 75 53 31 9 -13 -35 -57 97 75 53 31 9 -13 -35 119 97 75 53 31 9 -13 141 119 97 75 53 31 9 163 141 119 97 75 53 31 185 163 141 119 97 75 53 207 185 163 141 119 97 75 229 207 185 163 141 119 97 251 229 207 185 163 141 119 273 251 229 207 185 163 141
## 9 9 -4 -26 -48 -70 -92 -114 -136 18 -4 -26 -48 -70 -92 -114 40 18 -4 -26 -48 -70 -92 62 40 18 -4 -26 -48 -70 84 62 40 18 -4 -26 -48 106 84 62 40 18 -4 -26 128 106 84 62 40 18 -4 150 128 106 84 62 40 18 172 150 128 106 84 62 40 194 172 150 128 106 84 62 216 194 172 150 128 106 84 238 216 194 172 150 128 106 260 238 216 194 172 150 128 282 260 238 216 194 172 150
## 10 14 -12 -34 -56 -78 -100 -122 -144 10 -12 -34 -56 -78 -100 -122 32 10 -12 -34 -56 -78 -100 54 32 10 -12 -34 -56 -78 76 54 32 10 -12 -34 -56 98 76 54 32 10 -12 -34 120 98 76 54 32 10 -12 142 120 98 76 54 32 10 164 142 120 98 76 54 32 186 164 142 120 98 76 54 208 186 164 142 120 98 76 230 208 186 164 142 120 98 252 230 208 186 164 142 120 274 252 230 208 186 164 142
## 11 4 -3 -25 -47 -69 -91 -113 -135 19 -3 -25 -47 -69 -91 -113 41 19 -3 -25 -47 -69 -91 63 41 19 -3 -25 -47 -69 85 63 41 19 -3 -25 -47 107 85 63 41 19 -3 -25 129 107 85 63 41 19 -3 151 129 107 85 63 41 19 173 151 129 107 85 63 41 195 173 151 129 107 85 63 217 195 173 151 129 107 85 239 217 195 173 151 129 107 261 239 217 195 173 151 129 283 261 239 217 195 173 151
## 12 21 3 -19 -41 -63 -85 -107 -129 25 3 -19 -41 -63 -85 -107 47 25 3 -19 -41 -63 -85 69 47 25 3 -19 -41 -63 91 69 47 25 3 -19 -41 113 91 69 47 25 3 -19 135 113 91 69 47 25 3 157 135 113 91 69 47 25 179 157 135 113 91 69 47 201 179 157 135 113 91 69 223 201 179 157 135 113 91 245 223 201 179 157 135 113 267 245 223 201 179 157 135 289 267 245 223 201 179 157
## 13 15 5 -17 -39 -61 -83 -105 -127 27 5 -17 -39 -61 -83 -105 49 27 5 -17 -39 -61 -83 71 49 27 5 -17 -39 -61 93 71 49 27 5 -17 -39 115 93 71 49 27 5 -17 137 115 93 71 49 27 5 159 137 115 93 71 49 27 181 159 137 115 93 71 49 203 181 159 137 115 93 71 225 203 181 159 137 115 93 247 225 203 181 159 137 115 269 247 225 203 181 159 137 291 269 247 225 203 181 159
## 14 10 8 -14 -36 -58 -80 -102 -124 30 8 -14 -36 -58 -80 -102 52 30 8 -14 -36 -58 -80 74 52 30 8 -14 -36 -58 96 74 52 30 8 -14 -36 118 96 74 52 30 8 -14 140 118 96 74 52 30 8 162 140 118 96 74 52 30 184 162 140 118 96 74 52 206 184 162 140 118 96 74 228 206 184 162 140 118 96 250 228 206 184 162 140 118 272 250 228 206 184 162 140 294 272 250 228 206 184 162
## 15 8 -2 -24 -46 -68 -90 -112 -134 20 -2 -24 -46 -68 -90 -112 42 20 -2 -24 -46 -68 -90 64 42 20 -2 -24 -46 -68 86 64 42 20 -2 -24 -46 108 86 64 42 20 -2 -24 130 108 86 64 42 20 -2 152 130 108 86 64 42 20 174 152 130 108 86 64 42 196 174 152 130 108 86 64 218 196 174 152 130 108 86 240 218 196 174 152 130 108 262 240 218 196 174 152 130 284 262 240 218 196 174 152
## 16 6 15 -7 -29 -51 -73 -95 -117 37 15 -7 -29 -51 -73 -95 59 37 15 -7 -29 -51 -73 81 59 37 15 -7 -29 -51 103 81 59 37 15 -7 -29 125 103 81 59 37 15 -7 147 125 103 81 59 37 15 169 147 125 103 81 59 37 191 169 147 125 103 81 59 213 191 169 147 125 103 81 235 213 191 169 147 125 103 257 235 213 191 169 147 125 279 257 235 213 191 169 147 301 279 257 235 213 191 169
## 17 19 1 -21 -43 -65 -87 -109 -131 23 1 -21 -43 -65 -87 -109 45 23 1 -21 -43 -65 -87 67 45 23 1 -21 -43 -65 89 67 45 23 1 -21 -43 111 89 67 45 23 1 -21 133 111 89 67 45 23 1 155 133 111 89 67 45 23 177 155 133 111 89 67 45 199 177 155 133 111 89 67 221 199 177 155 133 111 89 243 221 199 177 155 133 111 265 243 221 199 177 155 133 287 265 243 221 199 177 155
## 18 3 -1 -23 -45 -67 -89 -111 -133 21 -1 -23 -45 -67 -89 -111 43 21 -1 -23 -45 -67 -89 65 43 21 -1 -23 -45 -67 87 65 43 21 -1 -23 -45 109 87 65 43 21 -1 -23 131 109 87 65 43 21 -1 153 131 109 87 65 43 21 175 153 131 109 87 65 43 197 175 153 131 109 87 65 219 197 175 153 131 109 87 241 219 197 175 153 131 109 263 241 219 197 175 153 131 285 263 241 219 197 175 153
## 19 5 1 -21 -43 -65 -87 -109 -131 23 1 -21 -43 -65 -87 -109 45 23 1 -21 -43 -65 -87 67 45 23 1 -21 -43 -65 89 67 45 23 1 -21 -43 111 89 67 45 23 1 -21 133 111 89 67 45 23 1 155 133 111 89 67 45 23 177 155 133 111 89 67 45 199 177 155 133 111 89 67 221 199 177 155 133 111 89 243 221 199 177 155 133 111 265 243 221 199 177 155 133 287 265 243 221 199 177 155
## 20 18 8 -14 -36 -58 -80 -102 -124 30 8 -14 -36 -58 -80 -102 52 30 8 -14 -36 -58 -80 74 52 30 8 -14 -36 -58 96 74 52 30 8 -14 -36 118 96 74 52 30 8 -14 140 118 96 74 52 30 8 162 140 118 96 74 52 30 184 162 140 118 96 74 52 206 184 162 140 118 96 74 228 206 184 162 140 118 96 250 228 206 184 162 140 118 272 250 228 206 184 162 140 294 272 250 228 206 184 162
## 21 17 19 -3 -25 -47 -69 -91 -113 41 19 -3 -25 -47 -69 -91 63 41 19 -3 -25 -47 -69 85 63 41 19 -3 -25 -47 107 85 63 41 19 -3 -25 129 107 85 63 41 19 -3 151 129 107 85 63 41 19 173 151 129 107 85 63 41 195 173 151 129 107 85 63 217 195 173 151 129 107 85 239 217 195 173 151 129 107 261 239 217 195 173 151 129 283 261 239 217 195 173 151 305 283 261 239 217 195 173
## 22 11 7 -15 -37 -59 -81 -103 -125 29 7 -15 -37 -59 -81 -103 51 29 7 -15 -37 -59 -81 73 51 29 7 -15 -37 -59 95 73 51 29 7 -15 -37 117 95 73 51 29 7 -15 139 117 95 73 51 29 7 161 139 117 95 73 51 29 183 161 139 117 95 73 51 205 183 161 139 117 95 73 227 205 183 161 139 117 95 249 227 205 183 161 139 117 271 249 227 205 183 161 139 293 271 249 227 205 183 161
For a demo that's easier to verify by eye, here I'll use three rows, five data columns on the LHS, and two data columns on the RHS:
df1 <- as.data.frame(cbind(sample(1:3),matrix(1:(3*5),3)));
df2 <- as.data.frame(cbind(sample(1:3),matrix(1:(3*2),3)));
df1;
## V1 V2 V3 V4 V5 V6
## 1 3 1 4 7 10 13
## 2 1 2 5 8 11 14
## 3 2 3 6 9 12 15
df2;
## V1 V2 V3
## 1 3 1 4
## 2 2 2 5
## 3 1 3 6
cbind(df1[,1],as.data.frame(rep(df1[,-1],each=ncol(df2)-1))-as.matrix(df2[match(df1[,1],df2[,1]),-1]));
## df1[, 1] V2 V2.1 V3 V3.1 V4 V4.1 V5 V5.1 V6 V6.1
## 1 3 0 -3 3 0 6 3 9 6 12 9
## 2 1 -1 -4 2 -1 5 2 8 5 11 8
## 3 2 1 -2 4 1 7 4 10 7 13 10
Notes:
Since the subtraction step must exclude the key column, rep() must operate on df1[,-1]. The -1 column subscript excludes the key column, which is assumed to be the first column in the data.frame.
The argument to each must be the number of subtrahends for each minuend, which means it also must exclude the key by subtracting one from ncol(df2).
Technically, when given a data.frame, rep() operates component-wise on the underlying list. But this works out for our purposes, because we can coerce back to data.frame with a call to as.data.frame(), and it's as if each individual element was replicated horizontally within its row. We are then ready with the widened data.frame to serve as the LHS of the subtraction.
In order to reorder the rows of the RHS, we first need to derive the correct row order. This can be done with match(df1[,1],df2[,1]). This basically says "for each key value in df1 in the order they occur in df1, return the row index in which that key value can be found in df2." The resulting index vector can then be used to row-index df2 to order it to align with df1. In the same index operation, we can exclude the key column of df2, fully preparing it for the cyclic subtraction, thus we have df2[match(df1[,1],df2[,1]),-1].
Unfortunately, it is not possible to subtract data.frames from each other, unless they are identical in size (otherwise you get the error ‘-’ only defined for equally-sized data frames). Thus I had to add an as.matrix() call on the RHS before subtracting. Another possible solution here could be to replicate the RHS to match the size of the LHS.
The key column had to be "restored" after the subtraction, hence the cbind() call wrapping the subtraction, which prepends the key column from df1 (df1[,1]).
I didn't bother to set any column names, since you haven't specified a requirement for them in your question. You can set them afterward if necessary via names()/setNames()/colnames()/dimnames().