A <- 1
B <- 2
C <- 3
names(C) <- 'LetterC'
# compare the following
c(A, B, C) # unnamed
nc(A, B, C) # named
nc(this=A, B, C) # respects override named (same as c() )
nc(this=A, B, C, use.names = TRUE) # preserve original name
if (FALSE) {
# throws errors if names not unique
nc(this=A, this=B, C)
nc(LetterC=A, B, C, use.names=TRUE)
}
# poor input choice names
nc(t.test(c(1:2))$p.value, t.test(c(3:4))$p.value)
# better to explicitly provide name
nc(T1 = t.test(c(1:2))$p.value,
T2 = t.test(c(3:4))$p.value)
# vector of unnamed inputs
A <- c(5,4,3,2,1)
B <- c(100, 200)
nc(A, B, C) # A's and B's numbered uniquely
c(A, B, C) # compare
nc(beta=A, B, C) # replacement of object name
# retain names attributes (but append object name, when appropriate)
names(A) <- letters[1:5]
nc(A, B, C)
nc(beta=A, B, C)
nc(A, B, C, use.names=TRUE)
# mix and match if some named elements work while others do not
c( nc(A, B, use.names=TRUE), nc(C))
if (FALSE) {
# error, 'b' appears twice
names(B) <- c('b', 'b2')
nc(A, B, C, use.names=TRUE)
}
# List input
A <- list(1)
B <- list(2:3)
C <- list('C')
names(C) <- 'LetterC'
# compare the following
c(A, B, C) # unnamed
nc(A, B, C) # named
nc(this=A, B, C) # respects override named (same as c() and list() )
nc(this=A, B, C, use.names = TRUE) # preserve original name
Run the code above in your browser using DataLab