Re: [R] Breaking up a Row in R (transpose)
Ok, I think I've got it this time. The problem was that you have two different types of data in the same data structure, the first row are the result's column names, then the actual numeric data. First, in what follows I've called your data.frame 'df1', df1 <- structure(list(A2 = structure(c(9L, 4L, ...etc... Now the code. dat <- apply(df1[-1, ], 2, as.numeric) nr <- nrow(dat) nc <- ncol(dat) names1 <- colnames(df1)[rep(c(TRUE, FALSE), nc/2)] names2 <- unique(unname(apply(df1, 2, function(x) as.character(x[1] res <- matrix(nrow=nc/2, ncol=2) inx <- as.matrix(rev(expand.grid(1:2, 1:(nc/2 res <- do.call(cbind, lapply(seq.int(nr), function(i){res[inx] <- dat[i, ]; matrix(res, ncol=2)})) res <- data.frame(res) rownames(res) <- names1 colnames(res) <- paste(names2, rep(seq.int(nr), each=2), sep=".") res I hope this is, finally, it. Rui Barradas marc212 wrote > > Short snippet- > > structure(list(A2 = structure(c(9L, 4L, 4L, 3L, 5L, 7L, 5L, 7L, > 6L, 1L, 1L, 1L, 3L, 4L, 5L, 5L, 2L, 5L, 3L, 4L, 4L, 8L, 4L, 3L, > 4L, 5L, 4L, 3L), .Label = c("4.957", "4.958", "4.959", "4.96", > "4.961", "4.962", "4.963", "4.964", "x"), class = "factor"), > A2.1 = structure(c(6L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 4L, 2L, > 4L, 2L, 5L, 4L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, > 2L, 2L, 2L), .Label = c("6.156", "6.157", "6.158", "6.159", > "6.161", "y"), class = "factor"), A3 = structure(c(9L, 2L, > 2L, 5L, 5L, 5L, 5L, 4L, 5L, 3L, 6L, 1L, 8L, 2L, 7L, 2L, 2L, > 6L, 3L, 1L, 2L, 2L, 2L, 5L, 3L, 4L, 8L, 3L), .Label = c("5.114", > "5.115", "5.116", "5.117", "5.118", "5.119", "5.12", "5.121", > "x"), class = "factor"), A3.1 = structure(c(2L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("4.227", > "y"), class = "factor"), A4 = structure(c(14L, 5L, 5L, 3L, > 7L, 6L, 7L, 1L, 5L, 4L, 2L, 9L, 5L, 12L, 7L, 11L, 11L, 4L, > 11L, 3L, 8L, 6L, 10L, 6L, 9L, 3L, 13L, 3L), .Label = c("5.204", > "5.207", "5.209", "5.21", "5.211", "5.212", "5.213", "5.214", > "5.215", "5.216", "5.218", "5.219", "5.221", "x"), class = "factor"), > A4.1 = structure(c(9L, 4L, 4L, 2L, 6L, 8L, 5L, 6L, 1L, 4L, > 4L, 2L, 6L, 3L, 2L, 4L, 4L, 6L, 4L, 8L, 4L, 3L, 6L, 4L, 2L, > 7L, 3L, 6L), .Label = c("2.564", "2.565", "2.566", "2.567", > "2.569", "2.57", "2.571", "2.572", "y"), class = "factor"), > B1 = structure(c(8L, 4L, 4L, 3L, 3L, 5L, 7L, 5L, 3L, 4L, > 2L, 4L, 2L, 3L, 4L, 4L, 5L, 4L, 4L, 6L, 4L, 2L, 2L, 5L, 5L, > 4L, 4L, 1L), .Label = c("7.273", "7.274", "7.275", "7.276", > "7.277", "7.278", "7.279", "x"), class = "factor"), B1.1 = > structure(c(8L, > 1L, 1L, 5L, 3L, 4L, 4L, 2L, 3L, 4L, 3L, 3L, 4L, 2L, 3L, 3L, > 3L, 3L, 3L, 3L, 5L, 4L, 7L, 4L, 3L, 5L, 5L, 6L), .Label = c("8.067", > "8.068", "8.069", "8.07", "8.071", "8.072", "8.073", "y"), class = > "factor"), > A1 = structure(c(6L, 5L, 5L, 3L, 3L, 1L, 4L, 4L, 3L, 1L, > 2L, 3L, 2L, 1L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 3L, 3L, 3L, 3L, > 2L, 3L, 5L), .Label = c("4.918", "4.919", "4.92", "4.921", > "4.922", "x"), class = "factor"), A1.1 = structure(c(6L, > 3L, 3L, 2L, 4L, 5L, 3L, 1L, 3L, 3L, 3L, 3L, 5L, 5L, 3L, 3L, > 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 1L, 3L, 4L), .Label = c("8.297", > "8.298", "8.299", "8.3", "8.301", "y"), class = "factor"), > B2 = structure(c(10L, 5L, 5L, 5L, 7L, 7L, 7L, 9L, 8L, 5L, > 2L, 8L, 5L, 4L, 2L, 6L, 3L, 2L, 9L, 5L, 4L, 2L, 5L, 5L, 1L, > 8L, 9L, 5L), .Label = c("7.272", "7.273", "7.274", "7.275", > "7.276", "7.277", "7.278", "7.279", "7.28", "x"), class = "factor"), > B2.1 = structure(c(6L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 4L, 3L, > 4L, 3L, 2L, 4L, 3L, 4L, 4L, 5L, 1L, 4L, 3L, 4L, 4L, 4L, 5L, > 3L, 3L, 5L), .Label = c("6.056", "6.058", "6.059", "6.06", > "6.061", "y"), class = "factor"), B3 = structure(c(10L, 1L, > 1L, 4L, 5L, 2L, 4L, 7L, 7L, 7L, 2L, 3L, 7L, 4L, 4L, 9L, 8L, > 7L, 6L, 7L, 5L, 4L, 6L, 9L, 7L, 8L, 6L, 4L), .Label = c("7.411", > "7.412", "7.413", "7.414", "7.415", "7.416", "7.417", "7.418", > "7.419", "x"), class = "factor"), B3.1 = structure(c(7L, > 3L, 3L, 3L, 5L, 4L, 4L, 2L, 5L, 3L, 4L, 4L, 4L, 3L, 1L, 3L, > 4L, 3L, 3L, 4L, 2L, 3L, 4L, 6L, 4L, 3L, 4L, 3L), .Label = c("4.05", > "4.052", "4.053", "4.054", "4.055", "4.056", "y"), class = "factor"), > B4 = structure(c(10L, 2L, 2L, 3L, 4L, 5L, 9L, 8L, 4L, 4L, > 6L, 4L, 3L, 5L, 4L, 5L, 8L, 7L, 4L, 4L, 4L, 6L, 4L, 6L, 2L, > 3L, 1L, 3L), .Label = c("7.468", "7.469", "7.47", "7.471", > "7.472", "7.473", "7.474", "7.475", "7.476", "x"), class = "factor"), > B4.1 = structure(c(6L, 4L, 4L, 3L, 4L, 4L, 1L, 3L, 4L, 5L, > 4L, 2L, 3L, 4L, 3L, 5L, 3L, 3L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, > 2L, 5L, 4L), .Label = c("2.274", "2.275", "2.276", "2.277", > "2.278", "y"), class = "factor"), C1 =
Re: [R] Breaking up a Row in R (transpose)
structure(list(A2 = structure(c(9L, 4L, 4L, 3L, 5L, 7L, 5L, 7L, 6L, 1L, 1L, 1L, 3L, 4L, 5L, 5L, 2L, 5L, 3L, 4L, 4L, 8L, 4L, 3L, 4L, 5L, 4L, 3L), .Label = c("4.957", "4.958", "4.959", "4.96", "4.961", "4.962", "4.963", "4.964", "x"), class = "factor"), A2.1 = structure(c(6L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 4L, 2L, 4L, 2L, 5L, 4L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("6.156", "6.157", "6.158", "6.159", "6.161", "y"), class = "factor"), A3 = structure(c(9L, 2L, 2L, 5L, 5L, 5L, 5L, 4L, 5L, 3L, 6L, 1L, 8L, 2L, 7L, 2L, 2L, 6L, 3L, 1L, 2L, 2L, 2L, 5L, 3L, 4L, 8L, 3L), .Label = c("5.114", "5.115", "5.116", "5.117", "5.118", "5.119", "5.12", "5.121", "x"), class = "factor"), A3.1 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("4.227", "y"), class = "factor"), A4 = structure(c(14L, 5L, 5L, 3L, 7L, 6L, 7L, 1L, 5L, 4L, 2L, 9L, 5L, 12L, 7L, 11L, 11L, 4L, 11L, 3L, 8L, 6L, 10L, 6L, 9L, 3L, 13L, 3L), .Label = c("5.204", "5.207", "5.209", "5.21", "5.211", "5.212", "5.213", "5.214", "5.215", "5.216", "5.218", "5.219", "5.221", "x"), class = "factor"), A4.1 = structure(c(9L, 4L, 4L, 2L, 6L, 8L, 5L, 6L, 1L, 4L, 4L, 2L, 6L, 3L, 2L, 4L, 4L, 6L, 4L, 8L, 4L, 3L, 6L, 4L, 2L, 7L, 3L, 6L), .Label = c("2.564", "2.565", "2.566", "2.567", "2.569", "2.57", "2.571", "2.572", "y"), class = "factor"), B1 = structure(c(8L, 4L, 4L, 3L, 3L, 5L, 7L, 5L, 3L, 4L, 2L, 4L, 2L, 3L, 4L, 4L, 5L, 4L, 4L, 6L, 4L, 2L, 2L, 5L, 5L, 4L, 4L, 1L), .Label = c("7.273", "7.274", "7.275", "7.276", "7.277", "7.278", "7.279", "x"), class = "factor"), B1.1 = structure(c(8L, 1L, 1L, 5L, 3L, 4L, 4L, 2L, 3L, 4L, 3L, 3L, 4L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 5L, 4L, 7L, 4L, 3L, 5L, 5L, 6L), .Label = c("8.067", "8.068", "8.069", "8.07", "8.071", "8.072", "8.073", "y"), class = "factor"), A1 = structure(c(6L, 5L, 5L, 3L, 3L, 1L, 4L, 4L, 3L, 1L, 2L, 3L, 2L, 1L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 3L, 5L), .Label = c("4.918", "4.919", "4.92", "4.921", "4.922", "x"), class = "factor"), A1.1 = structure(c(6L, 3L, 3L, 2L, 4L, 5L, 3L, 1L, 3L, 3L, 3L, 3L, 5L, 5L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 1L, 3L, 4L), .Label = c("8.297", "8.298", "8.299", "8.3", "8.301", "y"), class = "factor"), B2 = structure(c(10L, 5L, 5L, 5L, 7L, 7L, 7L, 9L, 8L, 5L, 2L, 8L, 5L, 4L, 2L, 6L, 3L, 2L, 9L, 5L, 4L, 2L, 5L, 5L, 1L, 8L, 9L, 5L), .Label = c("7.272", "7.273", "7.274", "7.275", "7.276", "7.277", "7.278", "7.279", "7.28", "x"), class = "factor"), B2.1 = structure(c(6L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 4L, 3L, 4L, 3L, 2L, 4L, 3L, 4L, 4L, 5L, 1L, 4L, 3L, 4L, 4L, 4L, 5L, 3L, 3L, 5L), .Label = c("6.056", "6.058", "6.059", "6.06", "6.061", "y"), class = "factor"), B3 = structure(c(10L, 1L, 1L, 4L, 5L, 2L, 4L, 7L, 7L, 7L, 2L, 3L, 7L, 4L, 4L, 9L, 8L, 7L, 6L, 7L, 5L, 4L, 6L, 9L, 7L, 8L, 6L, 4L), .Label = c("7.411", "7.412", "7.413", "7.414", "7.415", "7.416", "7.417", "7.418", "7.419", "x"), class = "factor"), B3.1 = structure(c(7L, 3L, 3L, 3L, 5L, 4L, 4L, 2L, 5L, 3L, 4L, 4L, 4L, 3L, 1L, 3L, 4L, 3L, 3L, 4L, 2L, 3L, 4L, 6L, 4L, 3L, 4L, 3L), .Label = c("4.05", "4.052", "4.053", "4.054", "4.055", "4.056", "y"), class = "factor"), B4 = structure(c(10L, 2L, 2L, 3L, 4L, 5L, 9L, 8L, 4L, 4L, 6L, 4L, 3L, 5L, 4L, 5L, 8L, 7L, 4L, 4L, 4L, 6L, 4L, 6L, 2L, 3L, 1L, 3L), .Label = c("7.468", "7.469", "7.47", "7.471", "7.472", "7.473", "7.474", "7.475", "7.476", "x"), class = "factor"), B4.1 = structure(c(6L, 4L, 4L, 3L, 4L, 4L, 1L, 3L, 4L, 5L, 4L, 2L, 3L, 4L, 3L, 5L, 3L, 3L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, 2L, 5L, 4L), .Label = c("2.274", "2.275", "2.276", "2.277", "2.278", "y"), class = "factor"), C1 = structure(c(6L, 4L, 4L, 4L, 4L, 5L, 3L, 3L, 3L, 1L, 2L, 2L, 4L, 2L, 4L, 4L, 5L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 3L, 3L, 1L), .Label = c("9.744", "9.745", "9.746", "9.747", "9.748", "x"), class = "factor"), C1.1 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("8.203", "y"), class = "factor"), C2 = structure(c(9L, 5L, 5L, 4L, 3L, 5L, 6L, 6L, 7L, 6L, 4L, 8L, 8L, 6L, 8L, 5L, 1L, 3L, 4L, 1L, 3L, 5L, 5L, 6L, 8L, 5L, 2L, 4L), .Label = c("9.916", "9.917", "9.918", "9.919", "9.92", "9.921", "9.922", "9.923", "x"), class = "factor"), C2.1 = structure(c(4L, 3L, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 1L), .Label = c("5.942", "5.943", "5.944", "y"), class = "factor"), C3 = structure(c(10L, 8L, 8L, 8L, 9L, 8L, 2L, 5L, 5L, 6L, 5L, 5L, 4L, 7L, 4L, 5L, 1L, 6L, 6L, 3L, 2L, 2L, 1L, 2L, 3L, 7L, 5L, 4L), .Label = c
Re: [R] Breaking up a Row in R (transpose)
Hello, again. marc212 wrote > > I have a pretty good computer with a lot of RAM and it just wont run this > code. My R crashes... > > Running this on a sample does not work either. > > Any advice? Thank you for all the help! > > Marc > What I'm saying is to use dput on a data sample. For instance, with 'orig' created as above, dput(orig) structure(c(5, 3, 5, 6, 4, 2, 6, 4, 6, 7, 3, 4, 7, 9, 7, 9, 9, 4), .Dim = c(3L, 6L), .Dimnames = list(c("0", "1", "2"), c("x", "y", "x", "y", "x", "y"))) If you post an example like this, we'll know better what to do. It's just a matter of copy&paste to an R session. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4610046.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
Hello, marc212 wrote > > I am not opposed to for loops just do not know how to implement them. > > > I am sorry for all the questions I am trying to learn. The posted code > does not work for me in my set I am getting a : > Error in `dimnames<-.data.frame`(`*tmp*`, value = list(c("A1", "A1.1", : > invalid 'dimnames' given for data frame > > Any help is much appreciated. > > Thank you. > Try commenting out the line dimnames <- list(... etc ...) You could also use dput() to post an example of your data. (Small example.) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609748.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
I am not opposed to for loops just do not know how to implement them. I am sorry for all the questions I am trying to learn. The posted code does not work for me in my set I am getting a : Error in `dimnames<-.data.frame`(`*tmp*`, value = list(c("A1", "A1.1", : invalid 'dimnames' given for data frame Any help is much appreciated. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609658.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
Hello, marc212 wrote > > I have the following: > Time A1 A1 B1 B1 C1 C2 > x y x y x y > 0 5 6 6 7 7 9 > 1 3 4 4 3 9 9 > 2 5 2 6 4 7 4 > > I want to change it to the following: > 0 1 2 > xy xy xy > A1 56 3 4 52 > B1 67 4 3 6 4 > etc for a much larger set > > I am sure there are ways to accomplish through a lot of for loops but I > feel there is most likely a function to use. > > Thank you. > Using Petr's Orig data.frame above, maybe this is what you want. cnames <- unique(colnames(Orig)) nc <- ncol(Orig)/length(cnames) res <- lapply(seq.int(nrow(Orig)), function(i){ x <- Orig[i, ] dim(x) <- c(length(cnames), nc) dimnames(x) <- list(cnames, LETTERS[seq_len(nc)]) t(x) }) names(res) <- rownames(Orig) res do.call(cbind, res) And it avoids loops. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609488.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
On Fri, May 04, 2012 at 11:11:47AM -0700, marc212 wrote: > I have something like 28 rows and 6000 columns. How would I configure this > with for loops. The transformation may be splitted into simpler pieces using a for loop over the 28 rows. Try the following. orig <- rbind( "0"=c(5, 6, 6, 7, 7, 9), "1"=c(3, 4, 4, 3, 9, 9), "2"=c(5, 2, 6, 4, 7, 4)) colnames(orig) <- rep(c("x", "y"), times=3) out <- matrix(nrow=ncol(orig)/2, ncol=2*nrow(orig)) for (i in seq.int(length=nrow(orig))) { out[, 2*(i-1) + 1:2] <- matrix(orig[i, ], nrow=nrow(out), ncol=2, byrow=TRUE) } out [,1] [,2] [,3] [,4] [,5] [,6] [1,]563452 [2,]674364 [3,]799974 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
I have something like 28 rows and 6000 columns. How would I configure this with for loops. Thank you. Marc -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609309.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Breaking up a Row in R (transpose)
On Thu, May 03, 2012 at 07:36:45PM -0700, marc212 wrote: > I have the following: > Time A1 A1 B1 B1 C1 C2 > x y x y x y > 0 5 6 6 7 7 9 > 1 3 4 4 3 9 9 > 2 5 2 6 4 7 4 > > I want to change it to the following: > 0 1 2 > xy xy xy > A1 56 3 4 52 > B1 67 4 3 6 4 > etc for a much larger set Hi. Try the following. # the example input Orig <- rbind( "0"=c(5, 6, 6, 7, 7, 9), "1"=c(3, 4, 4, 3, 9, 9), "2"=c(5, 2, 6, 4, 7, 4)) colnames(Orig) <- rep(c("x", "y"), times=3) # transformation Arr <- array(Orig, dim=c(nrow(Orig), 2, ncol(Orig)/2)) Arr , , 1# this is the required row 1 in the output [,1] [,2] [1,]56 [2,]34 [3,]52 , , 2# this is the required row 2 in the output [,1] [,2] [1,]67 [2,]43 [3,]64 , , 3 [,1] [,2] [1,]79 [2,]99 [3,]74 Arr1 <- aperm(Arr, perm=c(2, 1, 3)) d <- dim(Arr1) t(array(Arr1, dim=c(d[1]*d[2], d[3]))) [,1] [,2] [,3] [,4] [,5] [,6] [1,]563452 [2,]674364 [3,]799974 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list 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] Breaking up a Row in R (transpose)
I have the following: Time A1 A1 B1 B1 C1 C2 x y x y x y 0 5 6 6 7 7 9 1 3 4 4 3 9 9 2 5 2 6 4 7 4 I want to change it to the following: 0 1 2 xy xy xy A1 56 3 4 52 B1 67 4 3 6 4 etc for a much larger set I am sure there are ways to accomplish through a lot of for loops but I feel there is most likely a function to use. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.