Dear Ian,
it sounds more like an R data manipulation issue (which admittedly can be a pain) than a morphometric issue. Basically you want to convert from a "long" format to a "wide" format. You can read about this in multiple places on the internet, such as
http://www.cookbook-r.com/Manipulating_data/Converting_data_between_wide_and_long_format/
https://www.statmethods.net/management/reshape.html

I have tried my hand on your data, see code below. I'm sure there are 1000 other ways you can do this, including in a more elegant fashion... But in general what I did is to create some indexing variables for specimen and landmark and used them to restructure the data.

I hope this helps,
Carmelo


--


==================
Carmelo Fruciano
Institute of Biology
Ecole Normale Superieure - Paris
CNRS
http://www.fruciano.it/research/




##################
##################

data <- read.table("Trial2rawcoords.txt", header=TRUE)
# Import data

landmarks=30
# Number of landmarks

data$specimen=as.factor(unlist(lapply(seq_len(landmarks), function(x) rep(seq_len(landmarks)[x],30))))
data$landmark=as.factor(rep(1:30,30))
# Create two factors to index the various x,y coordinates

library(reshape)
data_wide=reshape(data,
           idvar = "specimen",
           timevar = "landmark",
           direction = "wide")
# Use reshape to convert from long to wide format
                
landmarknames=unlist(lapply(seq_len(landmarks), function(x) c(paste("x.",x,sep=""),paste("y.",x,sep=""))))
# Create ad hoc names to use for indexing

data_wide=cbind(data_wide$specimen,data_wide$genus.1,data_wide[,landmarknames])
# Get only the useful columns

######################
######################




On 09/08/2018 01:53, Ian F wrote:
I figured out what the issue was. thank you for your help. regrettably I have encountered another issue, any insight  would be much appreciated. I am trying to reformat a spreadsheet so that each individual is a row and each column represents an x or y coordinate. my data set consists of 30 specimens each with 30 landmarks. I keep getting the error code Error in `[<-`(`*tmp*`, j, 1, value = sub.data[1, 1]) :
   subscript out of bounds.

My data is in the link and my code is as follows.


# reformat data from imageJ into R compatible format.

data <- read.table(Trial2rawcoords.txt, header=TRUE)

len <- length(data$X)
overall.table <- matrix(nrow=len/30, ncol=(30*2)+1)
overall.length <- len/30
for(j in c(1:overall.length)) {
print(j)

sub.data <- as.matrix(data[ (1+30*(j-1)):((1+30*(j-1))+29), 2:4])

overall.table[j,1] <- sub.data[1, 1]
overall.table[j,2:3] <- sub.data[1, 2:3]
overall.table[j,4:5] <- sub.data[2, 2:3]
overall.table[j,6:7] <- sub.data[3, 2:3]
overall.table[j,8:9] <- sub.data[4, 2:3]
overall.table[j,10:11] <- sub.data[5, 2:3]
overall.table[j,12:13] <- sub.data[6, 2:3]
overall.table[j,14:15] <- sub.data[7, 2:3]
overall.table[j,16:17] <- sub.data[8, 2:3]
overall.table[j,18:19] <- sub.data[9, 2:3]
overall.table[j,20:21] <- sub.data[10, 2:3]
overall.table[j,22:23] <- sub.data[11, 2:3]
overall.table[j,24:25] <- sub.data[12, 2:3]
overall.table[j,26:27] <- sub.data[13, 2:3]
overall.table[j,28:29] <- sub.data[14, 2:3]
overall.table[j,30:31] <- sub.data[15, 2:3]
overall.table[j,32:33] <- sub.data[16, 2:3]
overall.table[j,34:35] <- sub.data[17, 2:3]
overall.table[j,36:37] <- sub.data[18, 2:3]
overall.table[j,38:39] <- sub.data[19, 2:3]
overall.table[j,40:41] <- sub.data[20, 2:3]
overall.table[j,42:43] <- sub.data[21, 2:3]
overall.table[j,44:45] <- sub.data[22, 2:3]
overall.table[j,46:47] <- sub.data[23, 2:3]
overall.table[j,48:49] <- sub.data[24, 2:3]
overall.table[j,50:51] <- sub.data[25, 2:3]
overall.table[j,52:53] <- sub.data[26, 2:3]
overall.table[j,54:55] <- sub.data[27, 2:3]
overall.table[j,56:57] <- sub.data[28, 2:3]
overall.table[j,58:59] <- sub.data[29, 2:3]
overall.table[j,60:61] <- sub.data[30, 2:3]
   }
# Confirm the above loop worked.

head(overall.table)
tail(overall.table)
# Assign the new table column names and write out the reformatted table to the working directory.

colnames(overall.table) <- c("number", "genus", "x1", "y1", "x2", "y2", "x3", "y3", "x4", "y4", "x5", "y5", "x6", "y6", "x7", "y7", "x8", "y8", "x9", "y9", "x10", "y10", "x11", "y11", "x12", "y12", "x13", "y13", "x14", "y14", "x15", "y15", "x16", "y16", "x17", "y17","x18","Y18","X19","Y19","X20","Y20","X21","Y21","X22","Y22","X23","Y23","X24","Y24","X25","Y25","X26","Y26","X27","Y27","X28","Y28","X29","Y29","X30","Y30")
write.table(overall.table, "reformat.txt")



On Thursday, August 2, 2018 at 1:32:02 PM UTC-4, Ian F wrote:

    I am trying to do an analysis of three specimens. I am using
    semi-landmarks and having trouble. perhaps someone can point out mt
    error? these are my results

    Generalized Procrustes Analysis
    with Partial Procrustes Superimposition

    -4 fixed landmarks
    12 semilandmarks (sliders)
    2-dimensional landmarks
    6 GPA iterations to converge
    Minimized Bending Energy used


    Consensus (mean) Configuration

                    X           Y
    [1,]  0.51447153 -0.03794928
    [2,]  0.36957021  0.11431610
    [3,] -0.11602250  0.19898458
    [4,] -0.40489951  0.11095030
    [5,] -0.43738229 -0.09965594
    [6,] -0.20913543 -0.09698422
    [7,]  0.04257626 -0.09131803
    [8,]  0.29799009 -0.04811314

    it should be three individuals with 4 landmarks and 4 sliders each.
    i want to perform PCA on the procrustes coordinates. my code and
    data are below. Im new to R and its probably an easy fix im just
    really confused. any help is greatly appreciated.






    Code:    Y <- arrayspecs(coordsrformat, k=2, p= ncol(coordsrformat)/2)

    slidermatrix

    Y.gpa <- gpagen(Y,curves=slidermatrix)
    summary(Y.gpa)
    plot(Y.gpa)

    Y.gpa <- gpagen(Y,curves=slidermatrix,ProcD=FALSE )
    summary(Y.gpa)
    plot(Y.gpa)
    a<-(Y.gpa$coords)
    plotTangentSpace(a)




    slider matrix:

    before        slide after
    5        6        7
    7        8        1
    1        2        3
    3        4        5
    1        8        7
    7        6        5
    5        4        3
    3        2        1
    1        2        3
    3        4        5
    5        6        7
    7        8        1


    coordsrformat:


    1630        1827        1530       1549        1198
    1345        908        1557      833        1840
    1027        1895        1223       1907        1417 1887
    2767        1081        2633       1581        2139
    2047        1693        1753       1535        1159
    1841        1067        2151       1009        2437 1071
    2956        928        2936      1692        2112
    2360        1300        1784       1304        1016
    1700        888        2084      832        2480 872



--
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
---
You received this message because you are subscribed to the Google Groups "MORPHMET" group. To unsubscribe from this group and stop receiving emails from it, send an email to morphmet+unsubscr...@morphometrics.org <mailto:morphmet+unsubscr...@morphometrics.org>.

--
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
--- You received this message because you are subscribed to the Google Groups "MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to morphmet+unsubscr...@morphometrics.org.

Reply via email to