Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
入力が 1、2、および 3 のベクトルであり、1 を .2 に、2 を .4 に、3 を .5 に送信する関数が必要です。(出力は同じ長さのベクトルである必要があります。) どうすればこれを達成できますか?
たとえば、
myVector<-c(1,2,3,2,3,3,1)
次に、関数
mapVector(myVector)
(.2,.4,.5,.4,.5,.5,.2) のようなベクトルを返す必要があります
install.packages("hash") library(hash) h<-hash(1:3, c(.2,.4,.5)) myVector<-c(1,2,3,2,3,3,1) sapply(myVector,function(x){return(h[[as.character(x)]])})