----- Forwarded message from David Katz -----

Date: Sun, 23 Sep 2012 07:47:36 -0400
From: David Katz
Reply-To: David Katz
Subject: Re: from excel to morphologika
To: [email protected]

This assumes (a) you have a four column excel document, where the first column contains the landmark names, (b) the excel file contains data for a single specimen, and (c) you do not care to retain landmark names as you proceed, since morphologika doesn't use them. 

Below, CAPITALIZED items in squiggle brackets ("{ }") require specification...

For a single file:

1. Save the excel file in .csv format.

2. Import to R...

file <- {FILE PATH}

imported <- 
     scan(file, skip={NUMBER OF ROWS TO SKIP IN EXCEL FILE SO THAT R BEGINS READING AT THE FIRST LINE OF DATA}, what = list(landmark="", X=double(0), Y=double(0), Z=double(0)), na.strings = c("NA", "na", ""), nlines={# OF ROWS OF DATA}, sep=",", flush=TRUE)

3. Convert to dataframe

df <- data.frame(imported$X,  imported$Y,  imported$Z)

4. export to txt file for use in morphologika

write.table(df, {SPECIFY THE PATH AND NAME OF THE TEXT FILE YOU WANT MORPHOLOGIKA TO READ}, sep="  ", quote=FALSE, row.names=FALSE, col.names=FALSE, append=TRUE) 

Note: if you want the text file to replace existing data any time you export something new to it from R, then "append=FALSE"

Note: you still need to type all of the introductory information morphologika requires into the text file. Also, if you want a wireframe, you need to specify the landmarks you want linked, below the coordinate data. All of this can be done in R. I have code for it, but it is tortuous and confusing b/c it is specific to the needs of my research.

Note: If you want to read multiple .csv files from a single folder, each with data for a single specimen, then you would begin as follows:

wd <- {SPECIFY FOLDER PATH}

setwd(wd)

specimens <- list.files(wd)

number.of.specimens <- length(specimens)

...then you would build a function to loop the scanning and conversion to data frame of Steps 2 and 3 over "number.of.specimens", generating a large array (or matrix). To export to a text file for morphologika

1. Put a single quote in front of each specimen name, b/c this is the format morphologika wants

specimen.names <- paste("'", specimens, sep="")

for (i in 1:number.of.specimens)
  {
    write.table(specimen.names[i], {SPECIFY THE PATH AND NAME OF THE TEXT FILE YOU WANT MORPHOLOGIKA TO READ}, sep="  ", quote=FALSE, row.names=FALSE, col.names=FALSE, append=TRUE)
    
    write.table(t({DATA.ARRAY}[,,i]), {SPECIFY THE PATH AND NAME OF THE TEXT FILE YOU WANT MORPHOLOGIKA TO READ}, sep=" ", quote=FALSE, row.names=FALSE, col.names=FALSE, append=TRUE)
 }

This write.table loop should also give you an idea of how you would write code so that R puts everything morphologika needs directly into the text file (rather than you typing it into the text file yourself). Don't forget to make sure you have "append" set the way you want it.

On Sun, Sep 23, 2012 at 12:24 AM, <[email protected]> wrote:


----- Forwarded message from marco milella -----

Date: Sat, 22 Sep 2012 02:38:52 -0400
From: marco milella
Reply-To: [email protected]
Subject: from excel to morphologika
To: [email protected]

Dear all, 
I'm trying to understand how to obtain a txt file with morphologika format from data collected via microscribe and saved as excel (rows: landmarks; three columns for each subject). Is any of you aware of any R/matlab script?
thanks
marco


----- End forwarded message -----







--
David Katz
Doctoral Candidate
Department of Anthropology--Evolutionary Wing
University of California, Davis
Young Hall 204



----- End forwarded message -----



Reply via email to