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

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

1
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.

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).

Value

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

Author(s)

Pedro Tarroso <ptarroso@cibio.up.pt>

See Also

dist d.gen midpoints idw

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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) 

phylin documentation built on Dec. 12, 2019, 5:07 p.m.