This is because of the presence of NA's in your "station_RT" column. If you use which(), it will give you the correct result:
station_list <- df[which(df$station_RT==142), ] best, huzefa On Mon, Feb 15, 2016 at 11:39 AM, Stefano Sofia < stefano.so...@regione.marche.it> wrote: > Dear R list users, > I am not able to perform a trivial filter of a data frame. > From a txt file (df_file.txt) of this form: > > sensor_RM station_RM place_RM municipality_RM Y_init_RM M_init_RM > D_init_RM Y_fin_RM M_fin_RM D_fin_RM goes_on notes sensor_RT station_RT net > Omogneneous > 2000 1510 Candelara Pesaro 1951 1 1 1997 8 4 NO NA NA NA NA NO > 2004 2230 Montemonaco Montemonaco 1951 1 1 2008 1 1 Y NA 1586 142 RT Y > 2011 2240 Diga_di_Carassai Carassai 1951 1 1 2008 1 1 Y > passata_in_RT_il_20140314_chiamata_Carassai 2976 708 RT Y > 2012 2250 Monterubbiano Monterubbiano 1951 1 1 2008 1 1 NO NA NA NA NA NO > 2014 1700 Fonte_Avellana Serra_S_Abbondio 1951 1 1 2005 1 4 Y NA 1206 109 > RT Y > 2016 1710 Pergola Pergola 1951 1 1 2008 1 7 Y NA 1198 108 RT Y > > I load it with > > df <- read.table(file="df_file.txt", header = TRUE, sep=" ", > stringsAsFactors=FALSE) > > There are 16 columns, some of them are integer and others are character. > > My problem is that > > station_list <- df[df$station_RT==142, ] > > should give me only the second row, while I get > > sensor_RM station_RM place_RM municipality_RM Y_init_RM M_init_RM > NA NA NA <NA> <NA> NA NA > 2 2004 2230 Montemonaco Montemonaco 1951 1 > NA.1 NA NA <NA> <NA> NA NA > D_init_RM Y_fin_RM M_fin_RM D_fin_RM goes_on notes sensor_RT > station_RT > NA NA NA NA NA <NA> <NA> NA > NA > 2 1 2008 1 1 Y <NA> 1586 > 142 > NA.1 NA NA NA NA <NA> <NA> NA > NA > net Omogneneous > NA <NA> <NA> > 2 RT Y > NA.1 <NA> <NA> > > Why? I struggled for a long time trying to understand where is the bug. > Could you please help me in that? > > Thank you > Stefano > > > ________________________________ > > 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. [[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.