r - How to access (index) a name/column by its name? -
r - How to access (index) a name/column by its name? -
let's assume have
x <- 1:3 names(x) <- c("has", "some", "names")
and want rename 1 of these names, some
good
. if know index, can this:
names(x)[2] <- "good"
what i'm trying find out how access name "some"
name. intuitively:
names(x)["some"] <- "good"
but not work, since names(x)
not have "names" (i.e. left hand side null
). tried set "names" of names(x)
:
names(names(x)) <- names(x)
which gives no error, names(x)
still not have "names" => still no access text possible... question is: how can set "names of names"?
note: i'm asking educational purposes improve understand how indexing strings works. there ways accomplish without setting "names of names", maybe this:
x <- ifelse(names(x) == "some", "good", names(x))
r indexing
Comments
Post a Comment