[SciPy-user] Equivalent to 'match' function in R?
Wes McKinney
wesmckinn@gmail....
Thu Jul 24 08:00:38 CDT 2008
Hi all,
I've been working with users lately who are transitioning from using R to
NumPy/Scipy. Some are accustomed to using the 'match' function, for
example:
> allData <- cbind(c(1,2,3,4,5), c(12, 19, 27, 38, 51))
> allData
[,1] [,2]
[1,] 1 12
[2,] 2 19
[3,] 3 27
[4,] 4 38
[5,] 5 51
> subData <- cbind(c(3,5,1), c(NA, NA, NA))
> subData
[,1] [,2]
[1,] 3 NA
[2,] 5 NA
[3,] 1 NA
> matchInd <- match(subData[,1], allData[,1])
> subData[,2] <- allData[matchInd,2]
> subData
[,1] [,2]
[1,] 3 27
[2,] 5 51
[3,] 1 12
>
>
> allData <- cbind(c(1,2,3,4,5), rep(NA,5))
> allData
[,1] [,2]
[1,] 1 NA
[2,] 2 NA
[3,] 3 NA
[4,] 4 NA
[5,] 5 NA
> subData <- cbind(c(3,5,1), c(27, 51, 12))
> subData
[,1] [,2]
[1,] 3 27
[2,] 5 51
[3,] 1 12
> matchInd <- match(subData[,1], allData[,1])
> allData[matchInd,2] <- subData[,2]
> allData
[,1] [,2]
[1,] 1 12
[2,] 2 NA
[3,] 3 27
[4,] 4 NA
[5,] 5 51
Before I reinvent the wheel, was curious if there was an equivalent function
elsewhere already. If not then some Cython/Pyrex is in order.
Thanks,
Wes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080724/f23debe0/attachment.html
More information about the SciPy-user
mailing list