AW: [R] Indexing dataframe

TEMPL Matthias Matthias.Templ at statistik.gv.at
Thu Sep 9 13:00:17 CEST 2004


Hi,

Use
Newdata <- subset(d2004, select=-c(concentration,stade))

See ?subset for details

Best,
Matthias

> -----Ursprüngliche Nachricht-----
> Von: Jacques VESLOT [mailto:jacques.veslot at cirad.fr] 
> Gesendet: Donnerstag, 09. September 2004 12:38
> An: r-help at stat.math.ethz.ch
> Betreff: [R] Indexing dataframe
> 
> 
> I am sorry to ask such question, but I can't find a solution...
> 
> I have a dataframe 'd2004' and I want to remove two columns: 
> 'd2004$concentration' and 'd2004$stade".
> 
> I could do it just as follows:
> 
> > names(d2004)
> 
>  [1] "Localite"       "Date"           "parcelle"       "maille"
> "presence.plant" "concentration"  "stade.culture"
>  [8] "stade"          "Trou"           "Horizon"        "Profondeur"
> 
> > d2004 <- d2004[, -c(6, 8)]
> 
> but I'd like to use column names (to avoid finding column 
> numbers each time).
> 
> I cannot find an easy way to operate...
> 
> I wonder why that works:
> > d2004[, "concentration"]
> 
> and this don't:
> > d2004 <- d2004[, -c("concentration", "stade")]
> 
> Thanks...
> 
> Jacques VESLOT / CIRAD
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read 
> the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list