----- Forwarded message from [email protected] -----

Date: Mon, 02 Jul 2012 22:00:43 -0700
From: [email protected]
Reply-To: [email protected]
Subject: Re: reading nts file format in R
To: [email protected]


----- Forwarded message from Graham Slater -----

Date: Tue, 26 Jun 2012 12:50:09 -0400
From: Graham Slater
Reply-To: Graham Slater
Subject: Re: reading nts file format in R
To: [email protected]

Hey Paolo et al,

I remember looking into this a while ago and not finding anything much available. I wrote a function to read nts files from TPS software but haven't gotten around to thoroughly bug checking it. I'm circulating it with the disclaimer therefore that it may be totally bad!  Briefly, the user just passes 3 arguments: the file name, the row in the original file containing column.names (default = NULL) and the row containing row names (default = NULL). It should return a matrix.

read.nts<- function(file.name, col.names = NULL, row.names = NULL) {


nts <- readLines(file.name);

if((strsplit(nts[1], " ")[[1]][1]) == "\"") {
begin <- 2;
} else {
begin <-1;
}
dim <- as.numeric(sub("L", "", strsplit(nts[begin], " ")[[1]][2:3]));

skip <- 0;
if(!is.null(col.names)) skip = skip + 1;
if(!is.null(row.names)) skip = skip +1;
nts.matrix <- matrix(data =as.numeric(unlist(apply(as.matrix(nts[(2+skip):(length(nts))]), 1, strsplit, split = " "))),nrow = dim[1], ncol = dim[2], byrow = T)


if(!is.null(col.names)) {
colnames(nts.matrix) <- strsplit(nts[col.names], " ")[[1]]
}
if(!is.null(row.names)) {
rownames(nts.matrix) <- strsplit(nts[row.names], " ")[[1]]
}


return(nts.matrix);
}


On Jun 26, 2012, at 9:35 AM, [email protected] wrote:

----- Forwarded message from [email protected] -----

Date: Tue, 19 Jun 2012 06:42:52 -0400
From: [email protected]
Reply-To: [email protected]
Subject: reading nts file format in R
To: [email protected]

Hi folks,
someones knows if exists a code to read nts files in R?
Thankyou
Paolo

--
Paolo Piras
Center for Evolutionary Ecology
and
Dipartimento di Scienze Geologiche, Università Roma Tre
Largo San Leonardo Murialdo, 1, 00146 Roma
Tel: +390657338000
email: [email protected]

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

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



------------------------------------------------------------
Graham Slater Ph. D.
Department of Ecology and Evolutionary Biology
University of California, Los Angeles
610 Charles E. Young Drive South
Los Angeles, CA 90095-1606

(424) 442-4348










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





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



Reply via email to