#Hello,

#I have would like to paste a single column of a matrix
# in pair wise fashion with other columns based upon
# even and odd column numbers.
# I can do it in a very clunky fashion and I know there
# must be a better way. below is a sample matrix and my extremely
# clunky code that gets the job done for a small matrix, but i plan to
# do this on a much grander scale. any help would be very much appreciated.

P.genotype.sample<-matrix(10,10,10)
P.genotype.sample[,1]<-c(2,2,1,5,1,1,5,6,1,3)
P.genotype.sample[,2]<-c(6,3,3,6,8,1,6,7,2,3)
P.genotype.sample[,3]<-c(2,2,2,3,3,2,2,2,3,3)
P.genotype.sample[,4]<-c(2,8,8,3,8,2,8,3,4,3)
P.genotype.sample[,5]<-c(3,3,8,3,6,1,1,1,1,3)
P.genotype.sample[,6]<-c(6,3,8,8,6,8,7,3,1,7)
P.genotype.sample[,7]<-c(1,5,5,1,5,1,1,5,5,5)
P.genotype.sample[,8]<-c(5,5,5,5,7,6,7,5,5,8)
P.genotype.sample[,9]<-c(5,5,8,5,5,5,5,2,5,2)
P.genotype.sample[,10]<-c(5,8,8,8,8,5,8,5,8,2)
P.genotype.sample

# I would like to paste column 1 with every odd column
# I would like to paste column 2 with every even column

#I know i can do it step by step in this fashion

Column.1.2_by_Column.3.4<-paste(P.genotype.sample[,1:2],P.genotype.sample
[,3:4])
Column.1.2_by_Column.3.4

Column.1.2_by_Column.5.6<-paste(P.genotype.sample[,1:2],P.genotype.sample
[,5:6])
Column.1.2_by_Column.5.6

Column.1.2_by_Column.7.8<-paste(P.genotype.sample[,1:2],P.genotype.sample
[,7:8])
Column.1.2_by_Column.7.8

Column.1.2_by_Column.9.10<-paste(P.genotype.sample[,1:2],P.genotype.sample
[,9:10])
Column.1.2_by_Column.9.10

Column.1.2.data.matrix<- matrix(20,20,4)

Column.1.2.data.list<-list(Column.1.2_by_Column.3.4,Column.1.2_by_Column.5.6
,
               Column.1.2_by_Column.7.8,Column.1.2_by_Column.9.10)
for (i in 1:4){
Column.1.2.data.matrix[,i]<-Column.1.2.data.list[[i]]
        }
Column.1.2.data.matrix

# However i will have many more data columns to compare to in a larger data
set
# and I was wondering if there was a more clever way to do this and still
# come up with the same result.

# Any help would be greatly appreciated

# Thanks in advance

Luke Neraas

lukasneraas.r@gmail.com

University of Alaska Fairbanks
School of Fisheries and Ocean Sciences
11120 Glacier Highway
UAF Fisheries Division
Juneau, AK 99801

	[[alternative HTML version deleted]]

