[R] How to delete rows

Michael Graber michael_graber at gmx.de
Wed Jul 27 18:43:52 CEST 2005


Dear R-users,

I am very new to R, so maybe my question is very easy to answer.
I have the following table:
TAB1<-data.frame(Name,Number), "Name" and "Number" are all character 
strings,
it looks like this:

Name  Number

ab      2

ab      2

NA     15

NA     15

NA     15

cd      3

ef      1

NA     15

NA     15

gh     15

gh     15

I want to delete all the rows which begin with "NA"
and all the rows where names are duplicates
(for example the second row).
I have tried this, but I only get numbers:

 for (i in 1:ZeileMax )  {if ( TAB1[[1]] [i] != "NA" ) 
{cat(TAB1[[1]][i],file = "Name.txt",fill= TRUE,append = TRUE ,sep = 
"");cat(TAB1[[2]][i], file="Number.txt", fill=TRUE,append=TRUE, sep="")}}
Name<-readLines("Name.txt")
Number<-readLines("Number.txt")
TAB<-data.frame(Name,Number)

 
Thanks in advance,

 

Michael Graber




More information about the R-help mailing list