[R] convert microns to nm in a messy dataset

Ivan Calandra c@|@ndr@ @end|ng |rom rgzm@de
Fri May 10 13:54:11 CEST 2019


Dear useRs,

Below is a sample of my dataset (I have more rows and columns).

As you can see in the 2nd column, there are values, the name of the parameter
('Sq' in that case), some integer ('45' in that case) and the unit ('µm' or
'nm').
I know how to extract the rows of interest (those with values), but they are
expressed in different units. All values following a line with the unit are
expressed in that unit, but the number of lines is not constant (sometimes each
value is expressed in a different unit so there will be a new unit line, but
there are sometimes several values in a row expressed in the same unit so
without unit lines in between). I hope this is clear (it should be with the
example provided).
This messy dataset comes from an external software so I don't have any means to
format the ways the data are collated. I have to find a way to deal with it in
R.

What I would like to do is convert the values in nm to µm; I just need to
multiply by 1000.

What I don't know is how to identify the values that are expressed in nm (all
values that follow a line with 'nm' until there is a line with 'µm').

I don't even know how I should search online because I don't know how this kind
of operation is called.
Any help is appreciated.

Thank you in advance.
Ivan


my.data <- structure(list(V1 = c("2019/05/10", "#", "#", "#", "2019/05/10",
"2019/05/10", "2019/05/10", "#", "#", "#", "2019/05/10", "#", "#", "#",
"2019/05/10", "#", "#", "#", "2019/05/10", "2019/05/10"), V19 =
c("0.2012800083", "45", "Sq", "µm", "0.3634383236", "0.4360454777",
"0.3767733568", "45", "Sq", "nm", "102.013048", "45", "Sq", "µm",
"0.1413840498", "45", "Sq", "nm", "65.4459715", "46.45802917")), row.names =
c(NA, 20L), class = "data.frame")

--
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra



More information about the R-help mailing list