We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vectors in can have dimensions and corresponding names, cf. dim() and dimnames(). They can concurrently have element names, cf. names(). For instance,
dim()
dimnames()
names()
> x <- matrix(1:6, nrow=2) > rownames(x) <- c("A", "B") > colnames(x) <- c("X", "Y", "Z") > names(x) <- letters[1:6] > x X Y Z A 1 3 5 B 2 4 6 attr(,"names") [1] "a" "b" "c" "d" "e" "f"
This allows us to access elements both by dimensional names as by element names, e.g.
> x[3] c 3 > x["c"] c 3 > x[1,2] [1] 3 > x["A","Y"] [1] 3
When subsetting by dimensions, we loose the element names, e.g.
> y <- x[,2:3] > y Y Z A 3 5 B 4 6 > names(y) NULL
Preserve element names also when subsetting by dimensions, e.g.
> y Y Z A 3 5 B 4 6 attr(,"names") [1] "c" "d" "e" "f" > y[1] c 3 > y["c"] c 3
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Background
Vectors in can have dimensions and corresponding names, cf.
dim()
anddimnames()
. They can concurrently have element names, cf.names()
. For instance,This allows us to access elements both by dimensional names as by element names, e.g.
Problem
When subsetting by dimensions, we loose the element names, e.g.
Wish
Preserve element names also when subsetting by dimensions, e.g.
The text was updated successfully, but these errors were encountered: