This vignette covers other functions that don’t fit in other vignettes, but still seem useful. Mainly this involves import and export, and some helper functions.
One of the most useful functions is
This can be used to export the contents of a coin to Excel at at any
point in its construction, and is very simple to run. We first build the
Then export to Excel:
This exports every data frame in the coin to a separate tab in the workbook, named according to its position in the coin. By default it excludes the Log of the coin, but this can be optionally included. The function is very useful for passing the results to people who don’t use R (let’s face it, that’s most people).
Data can also be imported directly into COINr from the COIN
Tool which is an Excel-based tool for building and analysing
composite indicators, similar in fact to COINr1. With the
import_coin_tool() function you can import data directly
from the COIN Tool to cross check or extend your analysis in COINr.
To demonstrate, we can take the example version of the COIN Tool, which you can download here. Then it’s as simple as running:
This will directly generate a coin from the COIN Tool.
COINr changed drastically from v0.6 to v1.0. So drastically that I
skipped several version numbers. From v1.0, the main object of COINr is
called a “coin” and this is different from the “COIN” used up to v0.6.x.
If you have worked in COINr before v1.0, you can use the
COIN_to_coin() function to convert old COINs into new
This comes with some limitations: any data sets present in the coin
will not be passed on unless
recover_dsets = TRUE. However,
if this is specified, the coin cannot be regenerated because it is not
possible to translate the log from the older COIN class (called the
“Method”) to the log in the new coin class. Still, the conversion avoids
having to reformat
Here we list some accessory functions that could be useful in some circumstances.
rank_df() function converts a data frame to ranks,
ignoring non-numeric columns. Taking some sample data:
This looks like
replace_df() function replaces values found anywhere
in a data frame with corresponding new values:
round_df() rounds to a specified number of decimal
places, ignoring non-numeric columns:
signif_df() is equivalent but for a number of
compare_df() function gives a detailed
comparison between two similar data frames that are indexed by a
specified column. This function is tailored to compare results in
composite indicators. Say you have a set of results from COINr and want
to cross check against a separate calculation. Often, you end up with a
data frame with the same columns, but possibly in a different order.
Rows could be in a different order but are indexed by an identifier,
here “uCode”. The
compare_df() function gives a detailed
comparison between the two data frames and points out any
We’ll demonstrate this by copying the example data frame, altering some values and seeing what happens:
# copy X1 <- X # change three values X1$GDP <- 101 X1$Population <- 10000 X1$Population <- 70000 # reorder X1 <- X1[order(X1$uCode), ] # now compare compare_df(X, X1, matchcol = "uCode") #> $Same #>  FALSE #> #> $Details #> Column TheSame Comment NDifferent #> 1 uCode TRUE Non-numerical and identical 0 #> 2 GDP FALSE Numerical and different at 5 sf. 1 #> 3 Population FALSE Numerical and different at 5 sf. 2 #> 4 LPI TRUE Numerical and identical to 5 sf. 0 #> #> $Differences #> $Differences$GDP #> uCode df1 df2 #> 3 BGR 53.23964 101 #> #> $Differences$Population #> uCode df1 df2 #> 1 AUT 8735.453 10000 #> 2 BEL 11429.336 70000
The output is a list with several entries. First, it tells us that the two data frames are not the same. The “Details” data frame lists each column and says whether it is identical or not, and how many different points there are. Finally, the “Differences” list has one entry for each column that differs, and details the value of the point from the first data frame compared to the value from the second.
From experience, this kind of output can be very helpful in quickly zooming in on differences between possibly large data frames of results. It is mainly intended for the use case described above, where the data frames are known to be similar, are of the same size, but we want to check for precise differences.
Full disclosure, I was also involved in the development of the COIN Tool↩︎