# People are having trouble efficiently subtracting things. For example taking the difference between the the Age Estimates and the Actual Ages. The reason is that these arrays have different sizes and so R needs to make a choice if you try to subtract them, and the choice is not always what you'd like. One natural way to deal with this is to make sure that everything involved the correct size. For starters, for some the short cuts I'd like to use it is useful to use "as.matrix" rather than "as.vector" in Load.txt. This should not change anything that you have already done, but will open up the possibilities for certain short cuts: Data=read.table("Data2.txt") Data=as.matrix(Data) Data[1:30,] Data[1:5,"E15"] PictData=read.table("PictData2.txt") PictData=as.matrix(PictData) PictData # Here are function that allow you repeat a row or a column n times: RepRow=function(V,n){ k=length(V) M=rep(1,k*n) dim(M)=c(n,k) M%*%diag(V) } RepCol=function(V,n){ k=length(V) M=rep(1,k*n) dim(M)=c(k,n) diag(V)%*%M } #Copy those functions into R and now try them out! V=c(3,4) n=5 RepRow(V,n) RepCol(V,n) # As an example of how to use this, here we take the Estimated Ages and subtract the Actual Ages. Estimates=Data[,4:23] Ages=PictData[,1] AgesR=RepRow(Ages,890) Diff=Estimates-AgesR # Here you took the first 20 column by 890 row array and subtracted the next 20 column by 890 row array to arrive at the need array of differences. We can look at the first 10 rows to see what you did. Estimates[1:10,] AgesR[1:10,] Diff[1:10,] # Sometimes the hardest part of doing this is choosing number of repeats, n. If you have an array whose shape you don't know, then type dim(YourArray") and you will see the number of Rows and Columns in the array. For example: dim(PictData) # Here's a more involved example that uses "dim". Suppose you wanted the absolute of the difference the Estimates and Actual Ages for all people with Gender=1 and Race=4 in both the Picture Data and the Estimate Data. First we form our true false vectors. Pict14=((PictData[,2]==1) & (PictData[,3]==4)) Est14=((Data[,2]==1) & (Data[,3]==4)) #Then we pick these out of our estimtes. Ages14=Ages[Pict14] Estimates14=Estimates[Est14,Pict14] dim(Estimates14) # We see there are 13 rows. So we apply the above procedure to find the need absolute differences AbDiff14. AgesR14=RepRow(Ages14,13) Diff14=Estimates14-AgesR14 AbDiff14=abs(Diff14) #We can look at it all... Estimates14 AgesR14 Diff14 AbDiff14 #and explore... summary(AbDiff14) # If you want it to ignore that it is an array, then type in c(AbDiff14) # For example: mean(c(AbDiff14)) hist(c(AbDiff14))