This looks like data for a morphometrics analysis so you should know about 
package geomorph. Data like yours is often stored as a three dimensional array 
so we switch to that format and then use the two.d.array() function in package 
geomorph:

Assuming your dataset is called dat: 

> arr <- array(as.matrix(dat[, -1]), dim=c(4, 2, 3))
> library(geomorph)
> mat <- two.d.array(arr)
> colnames(mat) <- paste0("p", rep(1:4, each=2), 
+      rep(c("x", "y"), 4), rep(1:4, each=2))
> mat
     p1x1 p1y1 p2x2 p2y2 p3x3 p3y3 p4x4 p4y4
[1,]    5   34   46   45   73   45   92   43
[2,]    7   26   48   42   72   44   90   43
[3,]    7   32   44   48   71   46   89   42
> dat2 <- data.frame(sample=1:3, mat)
> dat2
  sample p1x1 p1y1 p2x2 p2y2 p3x3 p3y3 p4x4 p4y4
1      1    5   34   46   45   73   45   92   43
2      2    7   26   48   42   72   44   90   43
3      3    7   32   44   48   71   46   89   42


-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352



-----Original Message-----
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of minikg
Sent: Wednesday, August 19, 2015 9:29 AM
To: r-help@r-project.org
Subject: [R] data format

Hi,

I have a dataset consisting of landmarks of each sample's  coordinates as
given below. 

landmark        X       Y       X       Y       X       Y
P1             5        34      7       26      7       32
P2           46 45      48      42      44      48
P3           73 45      72      44      71      46
P4           92 43      90      43      89      42


please help me to change my data format to

sample  p1x1    p1y1    p2x2    p2y2    p3x3    p3y3    p4x4    p4y4
1              5        34      46      45      73      45      92      43
2              7        26      48      42      72      44      90      43
3              7        32      44      48      71      46      89      42

Thanks 




--
View this message in context: 
http://r.789695.n4.nabble.com/data-format-tp4711278.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to