Unit conversions: Difference between revisions
Jump to navigation
Jump to search
(links added) |
(→Answer: prefixes and several units added) |
||
Line 12: | Line 12: | ||
We need conversion factors, which are listed below, and a code that does the actual conversion. | We need conversion factors, which are listed below, and a code that does the actual conversion. | ||
<t2b index="From,To,Observation" locations="Result,Description" unit="-"> | <t2b index="From,To,Type,Observation" locations="Result,Description" unit="-"> | ||
||Prefix|1| | |||
toe| | da||Prefix|10|deca | ||
h||Prefix|100|hecto | |||
k||Prefix|1000|kilo | |||
M||Prefix|1+e6|mega | |||
G||Prefix|1+e9|giga | |||
T||Prefix|1+e12|tera | |||
P||Prefix|1+e15|peta | |||
E||Prefix|1+e18|exa | |||
Z||Prefix|1+e21|zetta | |||
Y||Prefix|1+e24|yotta | |||
d||Prefix|0.1|deci | |||
c||Prefix|0.01|centi | |||
m||Prefix|0.001|milli | |||
μ||Prefix|1e-6|micro | |||
u||Prefix|1e-6|micro | |||
n||Prefix|1e-9|nano | |||
p||Prefix|1e-12|pico | |||
f||Prefix|1e-15|femto | |||
a||Prefix|1e-18|atto | |||
z||Prefix|1e-21|zepto | |||
y||Prefix|1e-24|yocto | |||
J|J|Unit|1|Joule, the base unit for energy | |||
Wh|J|Unit|3600|1 Wh = 1 Wh * 3600 s/h = 3600 Ws = 3600 MJ | |||
toe|J|Unit|3.5e+10|1 toe = 1000 kgoe = 1000 kg * 35 MJ/kg = 35000 MJ (energy as tons of oil equivalent) | |||
g|g|Unit|1|gram, the base unit for mass (although the definition is based on kg) | |||
ton|g|Unit|1e+6|metric ton | |||
tn|g|Unit|1e+6|metric ton | |||
s|s|Unit|1|second, the base unit for time | |||
min|s|Unit|60|minute | |||
h|s|Unit|3600|hour | |||
d|s|Unit|86400|day | |||
a|s|Unit|31557600|year (assuming 365.25 days per year) | |||
m|m|Unit|1|metre, the base unit of length | |||
in|m|Unit|0.0254|inch (strangely, some people still use these) | |||
ft|m|Unit|0.3048|foot = 12 inches | |||
mi|m|Unit|1609.344|mile = 5280 feet | |||
m3|m3|Unit|1|cubic metre, the basic unit of colume | |||
l|m3|Unit|1000|litre | |||
m^3|Unit|m3|1| | |||
</t2b> | </t2b> | ||
<rcode include="page:Opasnet_(R_library)|name:answer" | |||
variables=" | |||
name:amount|description:What is the amount?| | |||
name:fromunit|description:In what units is it?|type:text| | |||
name:tounit|description:To what unit do you want it?|type:text | |||
"> | |||
out <- convert.units(amount, tounit, fromunit) | |||
cat(paste(amount, fromunit, "=", out, tounit)) | |||
</rcode> | |||
==Rationale== | ==Rationale== |
Revision as of 05:48, 3 June 2012
Moderator:Jouni (see all) |
This page is a stub. You may improve it into a full page. |
Upload data
|
- The code related to this tool is now a part of Opasnet (R library).
Question
How to convert data from one unit to another in R?
Answer
We need conversion factors, which are listed below, and a code that does the actual conversion.
Obs | From | To | Type | Result | Description |
---|---|---|---|---|---|
1 | Prefix | 1 | |||
2 | da | Prefix | 10 | deca | |
3 | h | Prefix | 100 | hecto | |
4 | k | Prefix | 1000 | kilo | |
5 | M | Prefix | 1+e6 | mega | |
6 | G | Prefix | 1+e9 | giga | |
7 | T | Prefix | 1+e12 | tera | |
8 | P | Prefix | 1+e15 | peta | |
9 | E | Prefix | 1+e18 | exa | |
10 | Z | Prefix | 1+e21 | zetta | |
11 | Y | Prefix | 1+e24 | yotta | |
12 | d | Prefix | 0.1 | deci | |
13 | c | Prefix | 0.01 | centi | |
14 | m | Prefix | 0.001 | milli | |
15 | μ | Prefix | 1e-6 | micro | |
16 | u | Prefix | 1e-6 | micro | |
17 | n | Prefix | 1e-9 | nano | |
18 | p | Prefix | 1e-12 | pico | |
19 | f | Prefix | 1e-15 | femto | |
20 | a | Prefix | 1e-18 | atto | |
21 | z | Prefix | 1e-21 | zepto | |
22 | y | Prefix | 1e-24 | yocto | |
23 | J | J | Unit | 1 | Joule, the base unit for energy |
24 | Wh | J | Unit | 3600 | 1 Wh = 1 Wh * 3600 s/h = 3600 Ws = 3600 MJ |
25 | toe | J | Unit | 3.5e+10 | 1 toe = 1000 kgoe = 1000 kg * 35 MJ/kg = 35000 MJ (energy as tons of oil equivalent) |
26 | g | g | Unit | 1 | gram, the base unit for mass (although the definition is based on kg) |
27 | ton | g | Unit | 1e+6 | metric ton |
28 | tn | g | Unit | 1e+6 | metric ton |
29 | s | s | Unit | 1 | second, the base unit for time |
30 | min | s | Unit | 60 | minute |
31 | h | s | Unit | 3600 | hour |
32 | d | s | Unit | 86400 | day |
33 | a | s | Unit | 31557600 | year (assuming 365.25 days per year) |
34 | m | m | Unit | 1 | metre, the base unit of length |
35 | in | m | Unit | 0.0254 | inch (strangely, some people still use these) |
36 | ft | m | Unit | 0.3048 | foot = 12 inches |
37 | mi | m | Unit | 1609.344 | mile = 5280 feet |
38 | m3 | m3 | Unit | 1 | cubic metre, the basic unit of colume |
39 | l | m3 | Unit | 1000 | litre |
40 | m^3 | Unit | m3 | 1 |
Rationale
See also
References
Related files
<mfanonymousfilelist></mfanonymousfilelist>