Hi everybody,
Hope your are not all on holyday because I've got a problem that is going to
drive me crazy...
I would like to remove some rows from a dataframe. The rows correspond to
some
specific indexes which I can get by looking at the name in the first column
of my dataset. But I manage to get only the opposite of what I really want
(function #1)
#Function#1:
remove.func<-function(data){
Name<-as.character(data[,1])
indexZZ<-grep("ZZ",Name,value=FALSE)
data<-data[indexZZ,] # give me what I don't want
print(slide)
}
#Function#2:
remove.func<-function(data,Name){
Name<-as.character(data[,1])
indexZZ<-grep("ZZ",Name,value=FALSE)
data<-data[!indexZZ,] #doesn't work, give an empty dataframe
print(slide)
}
Thanks :|
Nolwenn Le Meur
********************************************
Nolwenn Le Meur
INSERM U533
Facult? de m?decine
1, rue Gaston Veil
44035 Nantes Cedex 1
France
Tel: (+33)-2-40-41-29-86 (office)
(+33)-2-40-41-28-44 (secretary)
Fax: (+33)-2-40-41-29-50
mail: nolwenn.lemeur at nantes.inserm.fr
data[-indexZZ,] as grep returns indices of the matching rows. On Wed, 6 Aug 2003, Nolwenn Le Meur wrote:> Hi everybody, > > Hope your are not all on holyday because I've got a problem that is going to > drive me crazy...Reading the documentation would avoid that!> I would like to remove some rows from a dataframe. The rows correspond to > some > specific indexes which I can get by looking at the name in the first column > of my dataset. But I manage to get only the opposite of what I really want > (function #1) > > #Function#1: > remove.func<-function(data){ > Name<-as.character(data[,1]) > indexZZ<-grep("ZZ",Name,value=FALSE) > data<-data[indexZZ,] # give me what I don't want > print(slide) > } > > #Function#2: > remove.func<-function(data,Name){ > Name<-as.character(data[,1]) > indexZZ<-grep("ZZ",Name,value=FALSE) > data<-data[!indexZZ,] #doesn't work, give an empty dataframe > print(slide) > } > > Thanks :| > > Nolwenn Le Meur > > ******************************************** > Nolwenn Le Meur > INSERM U533 > Facult? de m?decine > 1, rue Gaston Veil > 44035 Nantes Cedex 1 > France > > Tel: (+33)-2-40-41-29-86 (office) > (+33)-2-40-41-28-44 (secretary) > Fax: (+33)-2-40-41-29-50 > mail: nolwenn.lemeur at nantes.inserm.fr > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Nolwenn Le Meur wrote:> Hi everybody, > > Hope your are not all on holyday because I've got a problem that is going to > drive me crazy...No comment on that sentence, but please use the subject line ....> I would like to remove some rows from a dataframe. The rows correspond to > some > specific indexes which I can get by looking at the name in the first column > of my dataset. But I manage to get only the opposite of what I really want > (function #1) > > #Function#1: > remove.func<-function(data){ > Name<-as.character(data[,1]) > indexZZ<-grep("ZZ",Name,value=FALSE) > data<-data[indexZZ,] # give me what I don't want > print(slide) > } > > #Function#2: > remove.func<-function(data,Name){ > Name<-as.character(data[,1]) > indexZZ<-grep("ZZ",Name,value=FALSE) > data<-data[!indexZZ,] #doesn't work, give an empty dataframePlease read the manuals and learn how to index: data <- data[-indexZZ,] Uwe Ligges> print(slide) > } > > Thanks :| > > Nolwenn Le Meur > > ******************************************** > Nolwenn Le Meur > INSERM U533 > Facult? de m?decine > 1, rue Gaston Veil > 44035 Nantes Cedex 1 > France > > Tel: (+33)-2-40-41-29-86 (office) > (+33)-2-40-41-28-44 (secretary) > Fax: (+33)-2-40-41-29-50 > mail: nolwenn.lemeur at nantes.inserm.fr > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help