Learn R Programming

phylin (version 2.0.2)

extract.val: Extact pairwise values from a matrix in a specified order.

Description

This function extacts pairwise values from a matrix in a specified order in a user provided table.

Usage

extract.val(m, samples)

Arguments

m

Matrix with values to extract.

samples

Data frame with columns indicating pairs of samples to extract values. Names must correspond to column and row names in the matrix.

Value

Returns a vector containing the values from the matrix m in the order given in samples.

Details

This function extracts the values from a matrix in the same pairs of populations/samples given in a table. It is useful for merging data from a distance matrix of samples and the midpoints between samples (in conjuction with midpoints function).

See Also

dist d.gen midpoints idw

Examples

Run this code
# NOT RUN {
data(vipers)
data(d.gen)

# calculate midpoints
mp <- midpoints(vipers[,1:2])

# extract values from d.gen. Columns 1 and 2 of mp have the information 
# about source and target samples.   
pair.data <- extract.val(d.gen, mp[,1:2]) 

# it is easier to view in a plot:
plot(vipers[,1:2], pch=vipers[,3], main="Midpoints between samples", 
     xlab="Longitude", ylab="Latitude")
#trace all connecting lines between samples
sps <- rownames(vipers)
for (i in 1:nrow(mp)) 
{
    sp <- mp[i, 1:2] #source an target samples
    mask <- c(which(sps == sp[,1]), which(sps == sp[,2]))
    lines(vipers$x[mask], vipers$y[mask], lty=2, col='lightgrey')
}

#midpoints with genetic distance acentuated
points(mp[,3:4], col='red', pch=16, cex=pair.data*15+0.5) 

# }

Run the code above in your browser using DataLab