Relying on the thread here, I made R "dictionary" as follows:
boxes_sent <- vector(mode="list", length=4)
boxes_sent <- c("NE01", "NE02", "NE03", "NE04")
names(boxes_sent) <- c(seq(1:4))
boxes_rcvd <- vector(mode="list", length=4)
boxes_rcvd <- c("NW01", "NW02", "NW03", "NW04")
names(boxes_rcvd) <- c(seq(from = 13, to =16))
boxes_all <- c(boxes_rcvd, boxes_sent)
> boxes_all
13 14 15 16 1 2 3 4
"NW01" "NW02" "NW03" "NW04" "NE01" "NE02" "NE03" "NE04"
Calling names(boxes_all)[[1]]
returns "13" while boxes_all[[1]]
returns "NW01" both of which correspond to the first item on the list. However, I thought this would return "NE01" based on the key/value pair I established when I executed names(boxes_sent) <- c(seq(1:4))
. How can I modify so that calling names(boxes_all)[[1]]
returns "NE02"? In my dataset, I have 39 key/value pair for the dictionary.
I would like to use names()
to do this although I attempted environment as suggested in the thread here without success:
boxes_sent<-new.env()
boxes_sent[["NE01", "NE02", "NE03", "NE04"]]<-c(seq(1:4))
boxes_rcvd <- new.env()
boxes_rcvd[["NW01", "NW02", "NW03", "NW04"]]<-c(seq(from = 13, to =16))
Error in boxes_sent[[c("NE01", "NE02", "NE03", "NE04")]] <- c(seq(1:4)) :
wrong args for environment subassignment
Thanks for your time and attention.
R version 3.0.3