[R] Indexing dataframe

Jacques VESLOT jacques.veslot at cirad.fr
Thu Sep 9 12:38:13 CEST 2004


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




More information about the R-help mailing list