[R] Transform a data.frame with "; " sep column and another one in a a new one with the same two column but with repetitions

João Azevedo Patrício joao.patricio at gmx.pt
Fri Jul 4 14:50:53 CEST 2014


Hi,

I've been trying to solve this issue but with no success.

I have some data like this:

1 > TC	WC
2 > 0	Instruments & Instrumentation; Nuclear Science & Technology; 
Physics, Particles & Fields; Spectroscopy
3 > 0	Nanoscience & Nanotechnology; Materials Science, 
Multidisciplinary; Physics, Applied
4 > 2	Physics, Nuclear; Physics, Particles & Fields
5 > 0	Chemistry, Inorganic & Nuclear
6 > 2	Chemistry, Physical; Materials Science, Multidisciplinary; 
Metallurgy & Metallurgical Engineering

And I need to have this:

1 > TC	WC
2 > 0	Instruments & Instrumentation
2 > 0	Nuclear Science & Technology
2 > 0	Physics, Particles & Fields
2 > 0	Spectroscopy
3 > 0	Nanoscience & Nanotechnology
3 > 0	Materials Science, Multidisciplinary
3 > 0	Physics, Applied
4 > 2	Physics, Nuclear
4 > 2	Physics, Particles & Fields
5 > 0	Chemistry, Inorganic & Nuclear
6 > 2	Chemistry, Physical
6 > 2	Materials Science, Multidisciplinary
6 > 2	Metallurgy & Metallurgical Engineering

This means repeat the row for each element in WC and keeping the same 
value in TC. The goal is to check how many TC (sum) there are by WC, 
when WC is multiple.

i've tried to separate the column using strsplt but then I cannot keep 
the track of TC.

thanks in advance.
-- 
João Azevedo Patrício
Tel.: +31 91 400 53 63
Portugal
@ http://tripaforra.bl.ee

"Take 2 seconds to think before you act"



More information about the R-help mailing list