Dear Arun, thanks for the solution. however, for my data I am getting this warning message
Warning messages: 1: In mean.default(.value[0], ...) : argument is not numeric or logical: returning NA what can be the cause of it? Regards Nico On Tue, Oct 8, 2013 at 4:56 PM, arun <smartpink...@yahoo.com> wrote: > To make it matrix: > > > row.names(res)<- res[,1] > res1<- as.matrix(res[,-1]) > A.K. > > > > ----- Original Message ----- > From: arun <smartpink...@yahoo.com> > To: Nico Met <nicome...@gmail.com> > Cc: R help <r-help@r-project.org> > Sent: Tuesday, October 8, 2013 10:54 AM > Subject: Re: [R] matrix of mean values > > Try: > > d1$value<-as.numeric(gsub(",","",as.character(d1$value))) > library(reshape2) > res <- dcast(d1,loc~variables,value.var="value",mean) > A.K. > > > > ----- Original Message ----- > From: Nico Met <nicome...@gmail.com> > To: R help <r-help@r-project.org> > Cc: > Sent: Tuesday, October 8, 2013 10:47 AM > Subject: [R] matrix of mean values > > Dear all, I have a data set where I want to make a matrix of the mean > values using 3rd column (value). Where rows are unique loc and columns > would be variables. If there is one observation or no observation just > use NA. > > > > > dput(d1) > > structure(list(loc = structure(c(6L, 9L, 9L, 9L, 9L, 4L, 4L, > > 4L, 4L, 4L, 4L, 13L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, > > 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 10L, > > 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 1L, > > 3L, 3L, 3L, 2L), .Label = c("AX09_126", "AX09_628", "AX09_924", > > "IALA08_3299", "JA08_246", "JA08_3299", "JA08_408", "JE08_246", > > "JE08_3299", "JE08_408", "NO08_246", "NO08_408", "PP08_3299"), class = > "factor"), > > variables = structure(c(5L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, > > 7L, 7L, 7L, 7L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 3L, 3L, > > 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 1L, 5L, 5L, 5L, 6L, 6L, 7L, > > 7L, 7L, 7L, 7L, 7L, 7L, 3L, 7L, 4L, 4L, 4L, 7L, 7L, 7L, 7L > > ), .Label = c("i", "r", "s", "t", "x", "y", "z"), class = "factor"), > > value = structure(c(1L, 21L, 2L, 1L, 30L, 32L, 4L, 32L, 5L, > > 20L, 5L, 1L, 24L, 12L, 26L, 24L, 12L, 15L, 26L, 14L, 15L, > > 23L, 13L, 11L, 23L, 25L, 23L, 6L, 7L, 3L, 8L, 19L, 3L, 19L, > > 28L, 16L, 18L, 18L, 17L, 31L, 29L, 10L, 27L, 22L, 9L, 22L, > > 22L, 9L, 9L, 35L, 33L, 33L, 33L, 34L), .Label = c("0", "0,3333", > > "142,1", "1506,00006", "1520,66664", "170,36", "18,6185", > > "19,2933", "20,2125", "20,7423", "225,94", "23,2245", "24,3526", > > "24,3685", "24,4593", "242,84", "25,7422", "26,34", "26,5989", > > "30,33336284", "36,33336608", "39,913", "41,4933", "43,9104", > > "47,1241", "49,3467", "49,5715", "50,0037", "50,7974", "53,6667", > > "56,2778", "76", "76,5", "77,6667", "82"), class = "factor")), .Names = > c("loc", > > "variables", "value"), class = "data.frame", row.names = c(NA, > > -54L)) > > > > Thanks > > > > Nico > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > > [[alternative HTML version deleted]]
______________________________________________ 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.