I have an issue ans i posted it , so i would like to receive a solution please On Mon, Aug 31, 2015 at 8:35 PM, shawin [via R] < ml-node+s789695n4711689h58 at n4.nabble.com> wrote:> I have a data frame csv file and I'm trying to calculate median for each > group separately row by row . When I separate the data frame in two groups > and calculate the median for each one, I am getting an NA result for the > second group : > the data > x1 x2 x3 x4 x5 x6 x7 y1 y2 y3 y4 y5 y6 y7 y8 > 9.488404158 9.470895414 9.282433728 9.366707445 9.955383045 9.640816474 > 9.606262272 9.329651027 9.434541611 9.473922432 9.311412966 9.3154885 > 9.434977488 9.470895414 9.764258059 > 8.630629966 8.55831075 8.788391003 8.576231135 8.671587906 8.842979993 > 8.861958856 8.58330436 8.603596508 8.570129609 8.59798922 8.572686772 > 8.679751791 8.663950953 8.432875347 > 9.354748885 9.367668838 9.259952558 9.421538213 9.554635162 9.603744578 > 9.452197983 9.284228877 9.404607878 9.317737979 9.343115301 9.310644266 > 9.27227486 9.360337823 9.44706281 > 9.944863964 9.950427516 10.19101759 10.07350804 10.03269879 10.1307908 > 10.03487287 9.74609383 9.886379007 9.775472567 10.036596 9.544738458 > 9.699611598 9.911962567 > 9.625804277 > > > Code: > > rowN <- nrow(AT1) > MD1<-vector(length=rowN) > MD2<-vector(length=rowN) > > MD1[1:rowN]<-NA > MD2[1:rowN]<-NA > > > x<- AT1[,c(2,3,4,5,6,7,8) ] > write.csv(x,"x.csv",row.names=TRUE) > x<-as.matrix(x) > for(i in 2:rowN) { > MD1[i]=median(x[i,]) > } > write.csv(MD1,"MD1.csv",row.names=TRUE) > > y<- AT1[,c(9,10,11,12,13,14,15,16)] > write.csv(y,"y.csv",row.names=TRUE) > y<-as.matrix(y) > for(j in 2:rowN) { > MD2[j]=median(y[j,]) > } > write.csv(MD2,"MD2.csv",row.names=TRUE) > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689.html > To start a new topic under R help, email > ml-node+s789695n789696h75 at n4.nabble.com > To unsubscribe from R, click here > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=789695&code=c2hhd2lua2FyaW1AZ21haWwuY29tfDc4OTY5NXwtMjQ0MzkwMjQ1> > . > NAML > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >-- View this message in context: http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689p4711690.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Dear Shawin You probably did not get an answer because 1 - you seem to have posted in HTML which mangled your post into unreadability 2 - there seem to be lots of lines which do not do anything germane to the problem. Why not try summary(y) or str(y) before you convert it to a matrix and see what it says? On 31/08/2015 20:46, shawin wrote:> I have an issue ans i posted it , so i would like to receive a solution > please > > On Mon, Aug 31, 2015 at 8:35 PM, shawin [via R] < > ml-node+s789695n4711689h58 at n4.nabble.com> wrote: > >> I have a data frame csv file and I'm trying to calculate median for each >> group separately row by row . When I separate the data frame in two groups >> and calculate the median for each one, I am getting an NA result for the >> second group : >> the data >> x1 x2 x3 x4 x5 x6 x7 y1 y2 y3 y4 y5 y6 y7 y8 >> 9.488404158 9.470895414 9.282433728 9.366707445 9.955383045 9.640816474 >> 9.606262272 9.329651027 9.434541611 9.473922432 9.311412966 9.3154885 >> 9.434977488 9.470895414 9.764258059 >> 8.630629966 8.55831075 8.788391003 8.576231135 8.671587906 8.842979993 >> 8.861958856 8.58330436 8.603596508 8.570129609 8.59798922 8.572686772 >> 8.679751791 8.663950953 8.432875347 >> 9.354748885 9.367668838 9.259952558 9.421538213 9.554635162 9.603744578 >> 9.452197983 9.284228877 9.404607878 9.317737979 9.343115301 9.310644266 >> 9.27227486 9.360337823 9.44706281 >> 9.944863964 9.950427516 10.19101759 10.07350804 10.03269879 10.1307908 >> 10.03487287 9.74609383 9.886379007 9.775472567 10.036596 9.544738458 >> 9.699611598 9.911962567 >> 9.625804277 >> >> >> Code: >> >> rowN <- nrow(AT1) >> MD1<-vector(length=rowN) >> MD2<-vector(length=rowN) >> >> MD1[1:rowN]<-NA >> MD2[1:rowN]<-NA >> >> >> x<- AT1[,c(2,3,4,5,6,7,8) ] >> write.csv(x,"x.csv",row.names=TRUE) >> x<-as.matrix(x) >> for(i in 2:rowN) { >> MD1[i]=median(x[i,]) >> } >> write.csv(MD1,"MD1.csv",row.names=TRUE) >> >> y<- AT1[,c(9,10,11,12,13,14,15,16)] >> write.csv(y,"y.csv",row.names=TRUE) >> y<-as.matrix(y) >> for(j in 2:rowN) { >> MD2[j]=median(y[j,]) >> } >> write.csv(MD2,"MD2.csv",row.names=TRUE) >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689.html >> To start a new topic under R help, email >> ml-node+s789695n789696h75 at n4.nabble.com >> To unsubscribe from R, click here >> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=789695&code=c2hhd2lua2FyaW1AZ21haWwuY29tfDc4OTY5NXwtMjQ0MzkwMjQ1> >> . >> NAML >> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689p4711690.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Michael http://www.dewey.myzen.co.uk/home.html
Dear Michael , Thank you very much for your reply , kindly please can i send you the program and data please , y is shown a normal csv file no issue with it :( Kind Regards On Tue, Sep 1, 2015 at 8:36 AM, Michael Dewey-3 [via R] < ml-node+s789695n4711707h94 at n4.nabble.com> wrote:> Dear Shawin > > You probably did not get an answer because > 1 - you seem to have posted in HTML which mangled your post into > unreadability > 2 - there seem to be lots of lines which do not do anything germane to > the problem. > > Why not try summary(y) or str(y) before you convert it to a matrix and > see what it says? > > On 31/08/2015 20:46, shawin wrote: > > > I have an issue ans i posted it , so i would like to receive a solution > > please > > > > On Mon, Aug 31, 2015 at 8:35 PM, shawin [via R] < > > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711707&i=0>> > wrote: > > > >> I have a data frame csv file and I'm trying to calculate median for > each > >> group separately row by row . When I separate the data frame in two > groups > >> and calculate the median for each one, I am getting an NA result for > the > >> second group : > >> the data > >> x1 x2 x3 x4 x5 x6 x7 y1 y2 y3 y4 y5 y6 y7 y8 > >> 9.488404158 9.470895414 9.282433728 9.366707445 9.955383045 9.640816474 > >> 9.606262272 9.329651027 9.434541611 9.473922432 9.311412966 9.3154885 > >> 9.434977488 9.470895414 9.764258059 > >> 8.630629966 8.55831075 8.788391003 8.576231135 8.671587906 8.842979993 > >> 8.861958856 8.58330436 8.603596508 8.570129609 8.59798922 8.572686772 > >> 8.679751791 8.663950953 8.432875347 > >> 9.354748885 9.367668838 9.259952558 9.421538213 9.554635162 9.603744578 > >> 9.452197983 9.284228877 9.404607878 9.317737979 9.343115301 9.310644266 > >> 9.27227486 9.360337823 9.44706281 > >> 9.944863964 9.950427516 10.19101759 10.07350804 10.03269879 10.1307908 > >> 10.03487287 9.74609383 9.886379007 9.775472567 10.036596 > 9.544738458 > >> 9.699611598 9.911962567 > >> 9.625804277 > >> > >> > >> Code: > >> > >> rowN <- nrow(AT1) > >> MD1<-vector(length=rowN) > >> MD2<-vector(length=rowN) > >> > >> MD1[1:rowN]<-NA > >> MD2[1:rowN]<-NA > >> > >> > >> x<- AT1[,c(2,3,4,5,6,7,8) ] > >> write.csv(x,"x.csv",row.names=TRUE) > >> x<-as.matrix(x) > >> for(i in 2:rowN) { > >> MD1[i]=median(x[i,]) > >> } > >> write.csv(MD1,"MD1.csv",row.names=TRUE) > >> > >> y<- AT1[,c(9,10,11,12,13,14,15,16)] > >> write.csv(y,"y.csv",row.names=TRUE) > >> y<-as.matrix(y) > >> for(j in 2:rowN) { > >> MD2[j]=median(y[j,]) > >> } > >> write.csv(MD2,"MD2.csv",row.names=TRUE) > >> > >> > >> ------------------------------ > >> If you reply to this email, your message will be added to the > discussion > >> below: > >> > >> > http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689.html > >> To start a new topic under R help, email > >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711707&i=1> > >> To unsubscribe from R, click here > >> < > >> . > >> NAML > >> < > http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > > >> > > > > > > > > > > -- > > View this message in context: > http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689p4711690.html > > Sent from the R help mailing list archive at Nabble.com. > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711707&i=2> > 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. > > > > -- > Michael > http://www.dewey.myzen.co.uk/home.html > > ______________________________________________ > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4711707&i=3> > 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. > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689p4711707.html > To start a new topic under R help, email > ml-node+s789695n789696h53 at n4.nabble.com > To unsubscribe from R, click here > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=789695&code=bmF2aW5nMnVrQGdtYWlsLmNvbXw3ODk2OTV8LTczNzQxMTY0Ng==> > . > NAML > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >-- View this message in context: http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file-produce-Na-tp4711689p4711709.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hi Your code is highly complicated and difficult to understand without example data. Perhaps you want row medians for two groups x and y which are located in different columns of original data. MD1 <- apply(AT1[,c(2,3,4,5,6,7,8) ], 1, median) shall give you desired result without need of cycle and almost all other stuff. If there is NA in result, some of the value can be NA so after median you have to put na.rm=TRUE. consult ?apply ?summary ?str for explanation Cheers Petr> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of shawin > Sent: Monday, August 31, 2015 9:46 PM > To: r-help at r-project.org > Subject: Re: [R] Median on second group of CSV file produce Na > > I have an issue ans i posted it , so i would like to receive a solution > please > > On Mon, Aug 31, 2015 at 8:35 PM, shawin [via R] < > ml-node+s789695n4711689h58 at n4.nabble.com> wrote: > > > I have a data frame csv file and I'm trying to calculate median for > > each group separately row by row . When I separate the data frame in > > two groups and calculate the median for each one, I am getting an NA > > result for the second group : > > the data > > x1 x2 x3 x4 x5 x6 x7 y1 y2 y3 y4 y5 y6 y7 y8 > > 9.488404158 9.470895414 9.282433728 9.366707445 9.955383045 > 9.640816474 > > 9.606262272 9.329651027 9.434541611 9.473922432 9.311412966 > 9.3154885 > > 9.434977488 9.470895414 9.764258059 > > 8.630629966 8.55831075 8.788391003 8.576231135 8.671587906 > > 8.842979993 > > 8.861958856 8.58330436 8.603596508 8.570129609 8.59798922 > > 8.572686772 > > 8.679751791 8.663950953 8.432875347 > > 9.354748885 9.367668838 9.259952558 9.421538213 9.554635162 > > 9.603744578 > > 9.452197983 9.284228877 9.404607878 9.317737979 9.343115301 > > 9.310644266 > > 9.27227486 9.360337823 9.44706281 > > 9.944863964 9.950427516 10.19101759 10.07350804 10.03269879 > 10.1307908 > > 10.03487287 9.74609383 9.886379007 9.775472567 10.036596 > 9.544738458 > > 9.699611598 9.911962567 > > 9.625804277 > > > > > > Code: > > > > rowN <- nrow(AT1) > > MD1<-vector(length=rowN) > > MD2<-vector(length=rowN) > > > > MD1[1:rowN]<-NA > > MD2[1:rowN]<-NA > > > > > > x<- AT1[,c(2,3,4,5,6,7,8) ] > > write.csv(x,"x.csv",row.names=TRUE) > > x<-as.matrix(x) > > for(i in 2:rowN) { > > MD1[i]=median(x[i,]) > > } > > write.csv(MD1,"MD1.csv",row.names=TRUE) > > > > y<- AT1[,c(9,10,11,12,13,14,15,16)] > > write.csv(y,"y.csv",row.names=TRUE) > > y<-as.matrix(y) > > for(j in 2:rowN) { > > MD2[j]=median(y[j,]) > > } > > write.csv(MD2,"MD2.csv",row.names=TRUE) > > > > > > ------------------------------ > > If you reply to this email, your message will be added to the > > discussion > > below: > > > > http://r.789695.n4.nabble.com/Median-on-second-group-of-CSV-file- > produ > > ce-Na-tp4711689.html To start a new topic under R help, email > > ml-node+s789695n789696h75 at n4.nabble.com > > To unsubscribe from R, click here > > > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscr > > > ibe_by_code&node=789695&code=c2hhd2lua2FyaW1AZ21haWwuY29tfDc4OTY5NXwtM > > jQ0MzkwMjQ1> > > . > > NAML > > > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_vi > > > ewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces > > .BasicNamespace-nabble.view.web.template.NabbleNamespace- > nabble.naml.n > > amespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace- > nabb > > > le.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21na > > bble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml- > send_instant_em > > ail%21nabble%3Aemail.naml> > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Median-on- > second-group-of-CSV-file-produce-Na-tp4711689p4711690.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.________________________________ Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m. Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu. Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat. Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu. V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?: - vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu. - a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou. - trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech. - odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.