Thank you to Sarah Goslee and Ivan Calandra for their exhaustive explanations.
About Ivan Calandra's suggestion to put data in the right format adding a column "station" with values being either RM or RT, I would ask Ivan if he means to divide the initial data frame into two data frames, one for RM and one for RT. If this is the case, then I would find a way to link the two data frames, and this might not be the most efficient solution. But likely I miss the true meaning of the comment. Thank you Stefano ---------------------------------------------------------------------------------------- > > Message: 14 > Date: Wed, 7 Sep 2016 16:56:20 +0200 > From: Ivan Calandra <ivan.calan...@univ-reims.fr> > To: r-help@r-project.org > Subject: Re: [R] how to manage missing values correctly when importing > a data frame > Message-ID: <388bc333-497c-f806-e367-8aecb0a7d...@univ-reims.fr> > Content-Type: text/plain; charset=utf-8; format=flowed > > Hi Stefano, > > I agree that this behavior of R can be somewhat counter-intuitive, but > this can be seen as a safety procedure, so that no assumptions are made > and problems can be easily identified. > > I would think that in this case, the input data is in the wrong format. > Half the columns are for RM and the other for RT, but the headers are > exactly the same. The problem then happens because you actually have > only 3 lines of data for station RT but 4 for station RM. So it is > filled with NA. > > IMHO, it would be better to add a column "station" with values being > either RM or RT. In that case, you would not have whole NA lines. And > you would have less columns to work with. See what I mean? > > By the way, I like the matrix method for subsetting a data.frame, I find > it easier and more flexible (maybe someone will tell if there are any > drawbacks): > Storia_RM_RT[Storia_RM_RT$Station_RT==112, "Test_20151231"] > > HTH, > Ivan > > -- > Ivan Calandra, PhD > Scientific Mediator > University of Reims Champagne-Ardenne > GEGENAA - EA 3795 > CREA - 2 esplanade Roland Garros > 51100 Reims, France > +33(0)3 26 77 36 89 > ivan.calan...@univ-reims.fr > > ---------------------------------------------------------------------------------------- > Original Message: > > Dear R users, > I have a data frame with 22 columns, called Storia_RM_RT. Here the first 4 > rows: > > Station_RM Sensor_RM Place_RM Y_init_RM M_init_RM D_init_RM Long_cent_RM > Lat_cent_RM Height_RM Continues Station_RT Sensor_RT Place_RT Name1_RT > Name2_RT Long_cent_RT Lat_cent_RT Height_RT Actual_net Notes > Test_20141231 Test_20151231 > 1400 2701 Novafeltria 1959 1 1 12.289552 43.890057 293 NO NA NA NA NA NA NA > NA NA CAE NA NO NO > 1460 2702 Carpegna 1963 1 1 12.332614 43.778107 748 SI 702 2954 Carpegna > Carpegna Carpegna 12.340618 43.780575 715 RT NA NO NO > 1500 2703 Pesaro 1957 1 1 12.909822 43.910889 11 SI 112 1229 Pesaro > Villa_Fastiggi Villa_Fastiggi 12.86939 43.890610 22 RT NA YES YES > 1520 2704 Fano 1957 1 1 13.017591 43.840054 4 SI 152 2671 Fano Foce_Metauro > Metaurilia 13.053796 43.826328 7.12 RT NA YES YES > > I load it with > Storia_RM_RT <- read.table(file="Storia_RM_RT.txt", header = TRUE, sep=" ", > dec = ".", stringsAsFactors = FALSE) > > print(Storia_RM_RT$Test_20151231[Storia_RM_RT$Station_RM == 1500]) gives > [1] "YES" > > while > print(Storia_RM_RT$Omogenea_20151231[Storia_RM_RT$Station_RT == 112]) gives > [1] NA "YES" > > > I am struggling to understand why the query through the field Station_RT does > not work. > Could please somebody help me to manage correctly the missing values? Is the > mistake somewhere else? > > Thank you > Stefano Sofia ________________________________ AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. [[alternative HTML version deleted]] ______________________________________________ R-help@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.