# EXAMPLES for add_key()
#ex1 simple conversion of a vector
rti2 <- c("rpkg","obinna", "obianom")
add_key(rti2)
rti2
#ex2 add keys to a vector content for use in downstream processes
ver1 <- c("Test 1","Test 2","Test 3")
add_key(ver1)
#ex3 use keyed ver1 in for loop
for(i in ver1){
message(sprintf("%s is the key for this %s", i$key, i$value))
}
#ex4 use keyed ver1 in lapply loop
xl1 <- lapply(ver1,function(i){
message(sprintf("lapply - %s is the key for this %s", i$key, i$value))
})
# EXAMPLES for indexed()
#ex1 simple conversion of a vector
rti2 <- c("rpkg","obinna", "obianom")
indexed(rti2)
#ex2 add keys to a vector content for use in downstream processes
ver1 <- c("Test 1","Test 2","Test 3")
#ex3 use keyed ver1 in for loop
for(i in indexed(ver1)){
message(sprintf("%s is the key for this %s", i$key, i$value))
}
#ex4 use keyed ver1 in for loop
#specify name for key and value
for(i in indexed(ver1,k,v)){
message(
sprintf("%s is the new key for this value %s",
i$k, i$v))
}
#ex5 use keyed ver1 in lapply loop
xl1 <- lapply(indexed(ver1),function(i){
message(sprintf("lapply - %s is the key for this %s", i$key, i$value))
})
Run the code above in your browser using DataLab