[R] dealing with a messy dataset

jean-philippe jeanphilippe.fontaine at gssi.infn.it
Thu Oct 5 16:33:38 CEST 2017


dear Boris,

Thanks for your answer!

Yes it seems to  be a fixed-width format. I didn't remember this type of 
datasets since I am not used to analyze and process them.

Thanks anyway, it seems to fix the problem (I just need to reflect a bit 
more on the width of each feature)!


Cheers

Jean-Philippe

On 05/10/2017 16:19, Boris Steipe wrote:
> Is this a fixed width format?
> If so, read.fwf() in base, or read_fwf() in the readr package will solve the problem. You may need to trim trailing spaces though.
>
>
> B.
>
>
>
>
>> On Oct 5, 2017, at 10:12 AM, jean-philippe <jeanphilippe.fontaine at gssi.infn.it> wrote:
>>
>> dear R-users,
>>
>>
>> I am facing a quite regular and basic problem when it comes to dealing with datasets, but I cannot find any satisfying answer so far.
>> I have a messy dataset of galaxies like that :
>>
>> And XVIII          000214.5+450520  0.69 17   9 0.00  -8.7 26.8 6.44  6.78 < 6.65  -44  0.5 MESSIER031               0.6  1.54
>> PAndAS-03          000356.4+405319  0.10 17     0.00  -3.6 27.8 4.38                    2.8 MESSIER031               2.8  1.75
>> PAndAS-04          000442.9+472142  0.05 22     0.00  -6.6 23.1 5.59              -108  2.5 MESSIER031               2.5  1.75
>> PAndAS-05          000524.1+435535  0.06 31     0.00  -4.5 25.6 4.75               103  2.8 MESSIER031               2.8  1.75
>> ESO409-015         000531.8-280553  3.00 78  23 0.00 -14.6 24.1 8.10  8.25   8.10  769 -2.0 NGC0024                 -1.5 -2.05
>> AGC748778          000634.4+153039  0.61 70   3 0.00 -10.4 24.9 6.39  5.70   6.64  486 -1.9 NGC0253                 -1.5 -2.72
>> And XX             000730.7+350756  0.20 33   5 0.00  -5.8 27.1 5.26  5.70        -182  2.4 MESSIER031               2.4  1.75
>>
>> What I would like to do is to read this dataset, but I would like that the space between And and XVIII is not interpreted as 2 different columns but as the name of the galaxy in one column.
>> How is it possible to do so?
>>
>> For instance I did this data1<-read.table("lvg_table2.txt",skip=70,fill=T) where I used fill=T because the rows don't have the same number of features since R splits the name of the galaxies into 2 columns because of the space.
>>
>>
>> Best Regards, thanks in advance
>>
>>
>> Jean-Philippe Fontaine
>>
>> -- 
>> Jean-Philippe Fontaine
>> PhD Student in Astroparticle Physics,
>> Gran Sasso Science Institute (GSSI),
>> Viale Francesco Crispi 7,
>> 67100 L'Aquila, Italy
>> Mobile: +393487128593, +33615653774
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

-- 
Jean-Philippe Fontaine
PhD Student in Astroparticle Physics,
Gran Sasso Science Institute (GSSI),
Viale Francesco Crispi 7,
67100 L'Aquila, Italy
Mobile: +393487128593, +33615653774



More information about the R-help mailing list