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),]
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
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.
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>
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)