Re: [R] Change values in a dateframe-Speed TEST
Hi For a dataframe with name PaysContrat1 and with nrow(PaysContrat1) [1] 52366 the test of system.time is : system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule), FUN=function(x) {x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom),drop=TRUE];x} user system elapsed 14.030.00 14.04 system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) ,] )) user system elapsed 0.2 0.0 0.2 Michel Le 24/07/2013 15:29, arun a écrit : Hi Michel, You could try: df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),]) row.names(df1New)-1:nrow(df1New) df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),]) row.names(df2New)-1:nrow(df2New) identical(df1New,df1) #[1] TRUE identical(df2New,df2) #[1] TRUE A.K. - Original Message - From: Arnaud Michel michel.arn...@cirad.fr To: R help r-help@r-project.org Cc: Sent: Wednesday, July 24, 2013 2:39 AM Subject: [R] Change values in a dateframe Hello I have the following problem : The dataframe TEST has multiple lines for a same person because : there are differents values of Nom or differents values of Prenom but the values of Matricule or Sexe or Date.de.naissance are the same. TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L, 5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT ), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L, 2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine, Jeannine, Michel, Michele, Michèle, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) I would want to make homogeneous the information and would like built 2 dataframes : df1 wich has the value of Nom and Prenom of the first lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L, 5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeanine, Michel, Michele, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) df2 wich has the value of Nom and Prenom of the last lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged. df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L, 4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel, Michèle, Michelle, Victor), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) Thank for your helps Michel -- Michel ARNAUD Chargé de mission auprès du DRH DGDRD-Drh - TA 174/04 Av Agropolis 34398 Montpellier cedex 5 tel : 04.67.61.75.38 fax : 04.67.61.57.87 port: 06.47.43.55.31 __ 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] Change values in a dateframe-Speed TEST
But I just noticed that the two solutions are not comparable : the change concern only Nom and Prenom (solution Berend) and not also Sexe or Date.de.naissance orother variables (solution Arun) that can changed. But my question was badly put. Michel Le 25/07/2013 08:06, Arnaud Michel a écrit : Hi For a dataframe with name PaysContrat1 and with nrow(PaysContrat1) [1] 52366 the test of system.time is : system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule), FUN=function(x) {x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom),drop=TRUE];x} user system elapsed 14.030.00 14.04 system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) ,] )) user system elapsed 0.2 0.0 0.2 Michel Le 24/07/2013 15:29, arun a écrit : Hi Michel, You could try: df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),]) row.names(df1New)-1:nrow(df1New) df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),]) row.names(df2New)-1:nrow(df2New) identical(df1New,df1) #[1] TRUE identical(df2New,df2) #[1] TRUE A.K. - Original Message - From: Arnaud Michel michel.arn...@cirad.fr To: R help r-help@r-project.org Cc: Sent: Wednesday, July 24, 2013 2:39 AM Subject: [R] Change values in a dateframe Hello I have the following problem : The dataframe TEST has multiple lines for a same person because : there are differents values of Nom or differents values of Prenom but the values of Matricule or Sexe or Date.de.naissance are the same. TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L, 5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT ), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L, 2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine, Jeannine, Michel, Michele, Michèle, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) I would want to make homogeneous the information and would like built 2 dataframes : df1 wich has the value of Nom and Prenom of the first lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L, 5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeanine, Michel, Michele, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) df2 wich has the value of Nom and Prenom of the last lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged. df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L, 4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel, Michèle, Michelle, Victor), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) Thank for your helps Michel -- Michel ARNAUD Chargé de mission auprès du DRH DGDRD-Drh - TA 174/04 Av Agropolis 34398 Montpellier cedex 5 tel : 04.67.61.75.38 fax : 04.67.61.57.87 port: 06.47.43.55.31 __ 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
Re: [R] Change values in a dateframe-Speed TEST
On 25-07-2013, at 08:35, Arnaud Michel michel.arn...@cirad.fr wrote: But I just noticed that the two solutions are not comparable : the change concern only Nom and Prenom (solution Berend) and not also Sexe or Date.de.naissance orother variables (solution Arun) that can changed. But my question was badly put. Indeed:-) But that can be remedied with (small correction w.r.t. initial solution: drop=TRUE removed; not relevant here) r1 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule), FUN=function(x) {x[,1:ncol(x)] - x[1,1:ncol(x)];x}))) and r2 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule), FUN=function(x) {x[,1:ncol(x)] - x[nrow(x),1:ncol(x)];x}))) Less elegant than alternative with ave Berend Michel Le 25/07/2013 08:06, Arnaud Michel a écrit : Hi For a dataframe with name PaysContrat1 and with nrow(PaysContrat1) [1] 52366 the test of system.time is : system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule), FUN=function(x) {x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom),drop=TRUE];x} user system elapsed 14.030.00 14.04 system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) ,] )) user system elapsed 0.2 0.0 0.2 Michel Le 24/07/2013 15:29, arun a écrit : Hi Michel, You could try: df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),]) row.names(df1New)-1:nrow(df1New) df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),]) row.names(df2New)-1:nrow(df2New) identical(df1New,df1) #[1] TRUE identical(df2New,df2) #[1] TRUE A.K. - Original Message - From: Arnaud Michel michel.arn...@cirad.fr To: R help r-help@r-project.org Cc: Sent: Wednesday, July 24, 2013 2:39 AM Subject: [R] Change values in a dateframe Hello I have the following problem : The dataframe TEST has multiple lines for a same person because : there are differents values of Nom or differents values of Prenom but the values of Matricule or Sexe or Date.de.naissance are the same. TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L, 5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT ), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L, 2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine, Jeannine, Michel, Michele, Michèle, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) I would want to make homogeneous the information and would like built 2 dataframes : df1 wich has the value of Nom and Prenom of the first lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L, 5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeanine, Michel, Michele, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) df2 wich has the value of Nom and Prenom of the last lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged. df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L, 4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel, Michèle, Michelle, Victor), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
[R] Clarification of inputs for xyf function of kohonen package
For supervised version of the kohonen SOM (xyf), I wish to train a map, and then predict a property from the trained map. For the function xyf, whose basic call is: xyf(data, Y, grid) should the data argument contain the Y property? Or does it need to be excluded? e.g.: head(somdata) MEAS_TCSPLNSN GR NEUT 1 2.78 59.181090 33.74364 19.75361 66.57665 257.0368 2 1.49 49.047750 184.14598 139.07980 54.75052 326.8001 3 1.49 49.128902 183.58853 138.02768 55.54114 327.4739 4 2.201276 18.240331 19.20386 10.74748 62.04492 494.4161 5 2.201276 18.215522 19.18009 10.72446 61.87448 494.7409 6 1.276476 9.337769 14.16061 19.06902 14.99612 363.0020 Is the correct call like this: data.xyf - xyf(somdata, Y=somdata[1], ...) Or this: data.xyf - xyf(somdata[-1], Y=somdata[1], ...) Ben. __ 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] Change values in a dateframe-Speed TEST
Le 25/07/2013 08:50, Berend Hasselman a écrit : On 25-07-2013, at 08:35, Arnaud Michel michel.arn...@cirad.fr wrote: But I just noticed that the two solutions are not comparable : the change concern only Nom and Prenom (solution Berend) and not also Sexe or Date.de.naissance orother variables (solution Arun) that can changed. But my question was badly put. Indeed:-) But that can be remedied with (small correction w.r.t. initial solution: drop=TRUE removed; not relevant here) r1 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule), FUN=function(x) {x[,1:ncol(x)] - x[1,1:ncol(x)];x}))) and r2 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule), FUN=function(x) {x[,1:ncol(x)] - x[nrow(x),1:ncol(x)];x}))) Thank you but I keep {x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom)];x} because in the dataframe there are other variables that I do not want to change. I want change only Nom and Prénom PS : ?w.r.t. Michel Less elegant than alternative with ave Berend Michel Le 25/07/2013 08:06, Arnaud Michel a écrit : Hi For a dataframe with name PaysContrat1 and with nrow(PaysContrat1) [1] 52366 the test of system.time is : system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule), FUN=function(x) {x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom),drop=TRUE];x} user system elapsed 14.030.00 14.04 system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) ,] )) user system elapsed 0.2 0.0 0.2 Michel Le 24/07/2013 15:29, arun a écrit : Hi Michel, You could try: df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),]) row.names(df1New)-1:nrow(df1New) df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),]) row.names(df2New)-1:nrow(df2New) identical(df1New,df1) #[1] TRUE identical(df2New,df2) #[1] TRUE A.K. - Original Message - From: Arnaud Michel michel.arn...@cirad.fr To: R help r-help@r-project.org Cc: Sent: Wednesday, July 24, 2013 2:39 AM Subject: [R] Change values in a dateframe Hello I have the following problem : The dataframe TEST has multiple lines for a same person because : there are differents values of Nom or differents values of Prenom but the values of Matricule or Sexe or Date.de.naissance are the same. TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L, 5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT ), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L, 2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine, Jeannine, Michel, Michele, Michèle, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) I would want to make homogeneous the information and would like built 2 dataframes : df1 wich has the value of Nom and Prenom of the first lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L, 5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER, JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeanine, Michel, Michele, Michelle, Victor ), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor), Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = c(Matricule, Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names = c(NA, -11L)) df2 wich has the value of Nom and Prenom of the last lines of TEST when there are different values. The other values (Matricule or Sexe or Date.de.naissance) are unchanged. df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L, 91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L, 4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor), Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel, Michèle, Michelle, Victor), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L),
[R] Unable to install packages
Hi all. I am new to R. I have just installed R2.10.1 for my Windows 7 computer. When I go to Packages Install Packages on the drop-down list, I get the message: Warning: unable to access index for repository http://ftp.iitm.ac.in/cran/bin/windows/contrib/2.10 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10 Error in install.packages (Null, .libPaths () [1L], dependencies = NA, type = type) : no packages were specified Please advise suitably. Also suggest any good free online book/free online recognized course to * quickly* master R for data mining. [[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.
Re: [R] Saving multiple rda-files as one rda-file
Really no one has any suggestions on this issue? -- View this message in context: http://r.789695.n4.nabble.com/Saving-multiple-rda-files-as-one-rda-file-tp4672041p4672278.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.
[R] Error in initial value for qmatrix in msm function
*Hi R-helpers, **I am having a problem in running msm. I have a data with 200 ID, 4 state and transition is allowed for every state.**This is the number of transitions statetable.msm(Status,ID,data=dt) to from 1 2 3 4 1 0 54 181 100 2 11 14 7 11 3 49 12 42 10 4 75 6 3 11 I use the **crudeinits.msm to get initial value for the qmatrix. iniq2=crudeinits.msm(Status ~ Time, ID, data=dt, qmatrix=iniq) [,1] [,2] [,3] [,4] [1,] -0.03037171 0.004895739 0.016409791 0.009066183 [2,] 0.05213270 -0.137440758 0.033175355 0.052132701 [3,] 0.08045977 0.019704433 -0.116584565 0.016420361 [4,] 0.12234910 0.009787928 0.004893964 -0.137030995 When I run the msm function with qmatrix=iniq2 m1=msm( Status ~ Time, subject=ID, data = dt,qmatrix = iniq2) * *there is an error message Error in Pmat 1e-16 : invalid comparison with complex values Then I change the initial value become iniq2 [,1] [,2] [,3] [,4] [1,] -0.3 0.1 0.1 0.1 [2,] 0.1 -0.3 0.1 0.1 [3,] 0.1 0.1 -0.3 0.1 [4,] 0.1 0.1 0.1 -0.3 * *Then I run again the msm ** m1=msm( Status ~ Time, subject=ID, data = dt,qmatrix = iniq2) there in an error massage Error in optim(p$inits, lik.msm, hessian = hessian, gr = gr, ..., msmdata = msmdata, : function cannot be evaluated at initial parameters * *I have tried to use different initial value for several times, but the same error message always appear. **Do I need to add the data? Does anyone have any suggestions?Any suggestions would be much appreciated,** **Best wishes,** **Rianti* [[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.
[R] Neural Network Problem
Hello Professionals, I am new to R and am planning to use R for a Artificial Neural Network regression. I have 10 different scenarios for each observation (Input). For each scenario, there are 7 variables, which means 7 output. I have 1000 observations in total and I do have 1000 expected output.I want to use 800 observations for training and the rest for testing. Could any one provide a sample for my case? I don't quite understand the instructions from the packages. Appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Neural-Network-Problem-tp4672275.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.
[R] ask help!
Hi, In the R console, I have the following: runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' Can someone advise me of the solution of the problem? Mei-Yuan Chen Department of Finance NCHU, aiwan __ 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] flexible approach to subsetting data
Also, using the bigger example dataset: If you want all the 81 variables in the long form, it looks like you have to use 81 `grepl()` statements Wouldn't it be easier to just use: names(rtNew)-paste0(gsub(\\..*,,names(rtNew)),_,rep(1:5,each=81)) reshape(rtNew,direction=long,varying=1:ncol(rtNew),sep=_,timevar=m) A.K. - Original Message - From: arun smartpink...@yahoo.com To: Andrea Lamont alamont...@gmail.com Cc: R help r-help@r-project.org; David Carlson dcarl...@tamu.edu Sent: Wednesday, July 24, 2013 11:53 PM Subject: Re: [R] flexible approach to subsetting data Hi, It works in small dataset. rt- structure(list(sim = c(1L, 1L, 1L, 2L, 2L, 2L), txt.y.obs = c(5L, 4L, 3L, 6L, 7L, 9L), cont.y.obs = c(4L, 3L, 9L, 4L, 8L, 6L), ID = 1:6, obs.txt = c(5L, 2L, 4L, 8L, 4L, 7L), TE = c(5L, 7L, 4L, 3L, 5L, 8L), X1 = c(1L, 1L, 1L, 2L, 2L, 2L), sim.1 = c(4L, 7L, 5L, 3L, 5L, 9L), txt.y.obs.1 = c(3L, 5L, 7L, 9L, 5L, 4L), cont.y.obs.1 = c(3L, 4L, 8L, 9L, 4L, 5L), ID.1 = 1:6, obs.txt.1 = c(7L, 1L, 4L, 5L, 8L, 6L), TE.1 = c(5L, 6L, 3L, 4L, 9L, 10L), X1.1 = c(6L, 4L, 3L, 8L, 5L, 6L)), .Names = c(sim, txt.y.obs, cont.y.obs, ID, obs.txt, TE, X1, sim.1, txt.y.obs.1, cont.y.obs.1, ID.1, obs.txt.1, TE.1, X1.1 ), class = data.frame, row.names = c(NA, -6L)) rtr-reshape(rt, direction=long, varying=list( sim=grepl(sim, names(rt)), txt.y.obs=grepl(txt.y.obs, names(rt)), cont.y.obs=grepl(cont.y.obs, names(rt)), ID=grepl(ID, names(rt)), obs.txt=grepl(obs.txt, names(rt)), TE=grepl(TE, names(rt)), X1=grepl(X1, names(rt))), v.names= c(sim,txt.y.obs,cont.y.obs,ID,obs.txt, TE, X1), timevar=imputation) #Using a bigger dataset: set.seed(48) rtNew- as.data.frame(matrix(sample(1:50,405*5,replace=TRUE),ncol=405)) colnames(rtNew)-paste0(gsub(\\d+,,colnames(rtNew)),1:81) colnames(rtNew)[-c(1:81)]-paste(colnames(rtNew)[-c(1:81)],rep(1:4,each=81),sep=.) res- reshape(rtNew,direction=long,varying=list(V1=grepl(V1,names(rtNew)), V2=grepl(V2,names(rtNew)),V3=grepl(V3,names(rtNew)),V4=grepl(V4,names(rtNew)), V5=grepl(V5,names(rtNew)),V6=grepl(V6,names(rtNew)),V7=grepl(V7,names(rtNew))), v.names=c(V1,V2,V3,V4,V5,V6,V7),timevar=imputation) #works #When I forgot to close the list bracket: reshape(rtNew,direction=long,varying=list(V1=grepl(V1,names(rtNew)), V2=grepl(V2,names(rtNew)),V3=grepl(V3,names(rtNew)),V4=grepl(V4,names(rtNew)), V5=grepl(V5,names(rtNew)),V6=grepl(V6,names(rtNew)),V7=grepl(V7,names(rtNew)), v.names=c(V1,V2,V3,V4,V5,V6,V7),timevar=imputation)) #Error in reshapeLong(data, idvar = idvar, timevar = timevar, varying = varying, : # 'varying' arguments must be the same length Though, your code looks fine with respect to closing brackets. A.K. - Original Message - From: Andrea Lamont alamont...@gmail.com To: David Carlson dcarl...@tamu.edu Cc: R help r-help@r-project.org Sent: Wednesday, July 24, 2013 9:41 PM Subject: Re: [R] flexible approach to subsetting data Hi, all: I have a follow-up question. I have 81 variables in my dataset (all of which are repeated). Reshape seems to give me an error whenever more than six variables are used. The error message is this: Error in reshapeLong(data, idvar = idvar, timevar =timevar , varying = varying, : 'varying arguments must be the same length. I have tested the lengths of all the variables, and they are all equal. Further, when I mix up the variables used in the reshape function, it works -- so long as I keep the number of variables used under six. As soon as I add the seventh variable (regardless of what it is), I receive this error. #This works: rtr-reshape(rt, direction=long, varying=list( sim=grepl(sim, names(rt)), txt.y.obs=grepl(txt.y.obs, names(rt)), cont.y.obs=grepl(cont.y.obs, names(rt)), ID=grepl(ID, names(rt)), obs.txt=grepl(obs.txt, names(rt)), TE=grepl(TE, names(rt))), v.names= c(sim,txt.y.obs,cont.y.obs,ID,obs.txt, TE), timevar=imputation) #The addition of one more variable creates an error. The problem is not with X1. rtr-reshape(rt, direction=long, varying=list( sim=grepl(sim, names(rt)), txt.y.obs=grepl(txt.y.obs, names(rt)), cont.y.obs=grepl(cont.y.obs, names(rt)), ID=grepl(ID, names(rt)), obs.txt=grepl(obs.txt, names(rt)), TE=grepl(TE, names(rt)), X1=grepl(X1, names(rt))), v.names= c(sim,txt.y.obs,cont.y.obs,ID,obs.txt, TE, X1), timevar=imputation) On Tue, Jul 23, 2013 at 5:00 PM, David Carlson dcarl...@tamu.edu wrote: Actually the .0 on the first variable is not needed. You could modify the reshape() call to search for the base name of each variable so you would not need to change the code if the number of replications changes: reshape(df5, direction=long, v.names=c(dose, resp), varying=list(dose=grepl(dose, names(df5)), resp=grepl(resp, names(df5)) ) ) - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From:
Re: [R] ask help!
On 07/25/2013 07:44 PM, mei_yuan wrote: Hi, In the R console, I have the following: runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' Can someone advise me of the solution of the problem? Mei-Yuan Chen Hi Mei-Yuan, .Random.seed should be a vector of numeric values. Somehow this has been set to an object of type list: .Random.seed-list(.Random.seed) runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' I would suggest quitting R and _not_ saving the session, then restarting and trying: runif(10) again. Jim __ 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] Unable to install packages
Hello, Is there any reason for you to install an almost 3-year-old version of R? Regards, Pascal 2013/7/25 Arnab Chakrabarti chakrabarti.ar...@gmail.com Hi all. I am new to R. I have just installed R2.10.1 for my Windows 7 computer. When I go to Packages Install Packages on the drop-down list, I get the message: Warning: unable to access index for repository http://ftp.iitm.ac.in/cran/bin/windows/contrib/2.10 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10 Error in install.packages (Null, .libPaths () [1L], dependencies = NA, type = type) : no packages were specified Please advise suitably. Also suggest any good free online book/free online recognized course to * quickly* master R for data mining. [[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.
Re: [R] ask help!
-- Helios de Rosario Martínez Researcher El día 25/07/2013 a las 11:44, mei_yuan mei_y...@dragon.nchu.edu.tw escribió: Hi, In the R console, I have the following: runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' It seems you have overwritten the default value of the variable .Random.seed. Delete it and try again: rm(.Random.seed) runif(10) INSTITUTO DE BIOMECÁNICA DE VALENCIA Universidad Politécnica de Valencia • Edificio 9C Camino de Vera s/n • 46022 VALENCIA (ESPAÑA) Tel. +34 96 387 91 60 • Fax +34 96 387 91 69 www.ibv.org Antes de imprimir este e-mail piense bien si es necesario hacerlo. En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección de Datos de Carácter Personal, le informamos de que el presente mensaje contiene información confidencial, siendo para uso exclusivo del destinatario arriba indicado. En caso de no ser usted el destinatario del mismo le informamos que su recepción no le autoriza a su divulgación o reproducción por cualquier medio, debiendo destruirlo de inmediato, rogándole lo notifique al remitente. __ 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] ask help!
No R version was stated, but this is not the behaviour of R-patched so you could update. On 25/07/2013 11:01, Jim Lemon wrote: On 07/25/2013 07:44 PM, mei_yuan wrote: Hi, In the R console, I have the following: runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' Can someone advise me of the solution of the problem? Mei-Yuan Chen Hi Mei-Yuan, .Random.seed should be a vector of numeric values. Somehow this has been set to an object of type list: .Random.seed-list(.Random.seed) runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' I would suggest quitting R and _not_ saving the session, then restarting and trying: runif(10) again. Jim __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] How to split two levels several times?
Hi Rui once more thank you for your help. But the code does so far not solve the problem because it still treats rows 17-22 (repeated appearance of electrode1) as one single level. However as can be seen by rows 1-3 (or rows 17-19 and rows 20-22) and the order of the length variable (row 1 = 5.7, row 2 = 6.3, row 3 = 6.2) electrode1 consists only of 3 rows. Maybe that was not made absolutely clear by me. As described in my mail before if by chance (or systematically) it happens to be that electrode1 appears right after each other in the table then the code should split it “half way”. So idx should not return [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 but instead 6 times number 4 at the end [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 Do you have any solution? Gesendet: Mittwoch, 24. Juli 2013 um 23:47 Uhr Von: Rui Barradas ruipbarra...@sapo.pt An: dennis1...@gmx.net Cc: r-help@r-project.org Betreff: Re: Aw: Re: Re: [R] How to split two levels several times? Hello, As for the first question, note that in the case you describe, the resulting list of df's will not be a split of the original, there will be a duplication in the final 4-1 and 1-3. The following is a hack but will do it. lens - rle(as.character(XXX$electrode))$lengths m - length(lens) %/% 2 idx - rep(1:m, sapply(1:m, function(.m) sum(lens[(2*.m - 1):(2*.m)]))) if(length(lens) %% 2 != 0) idx - c(idx, rep(m + 1, lens[length(lens)])) sp - split(XXX, idx) if(length(lens) %% 2 != 0){ idx2 - sp[[m]]$electrode == sp[[m]]$electrode[nrow(sp[[m]])] sp[[m + 1]] - rbind(sp[[m]][idx2, ], sp[[m + 1]]) } sp As for the second question, I'm not understanding it, can you post sample output? Rui Barradas Em 24-07-2013 13:58, dennis1...@gmx.net escreveu: Hi Rui the splitting code worked fine. Thanks for your help. Now I realized that the code cannot handle a table with levels that by chance (or systematically) repeatedly appear after each other. For instance this may happen if I need to extract the final two pairs of the table XXX below: electrode4+electrode1 and electrode1+electrode3. lens - rle(as.character(XXX$electrode))$lengths will return 3 2 3 2 6 6 3 and not 3 2 3 2 6 3 3 3 because it counts electrode1 double. split(XXX, idx) will produce 3 incorrect outputs instead of the required 4. This will also occur if I have systematic combinations 1-4 after each other for instance in a new table “XX” below where electrode4 appears twice. Is there a way to make splitting half-way between two of the same levels possible by predefining the length of each individual level? This would make the splitting code more robust. Thanks for advice. This is the table XXX electrode length electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode2 11.4 electrode2 9.7 electrode3 14.2 electrode3 14.8 electrode3 12.6 electrode2 11.4 electrode2 9.7 electrode4 17.0 electrode4 16.3 electrode4 17.8 electrode4 18.3 electrode4 16.9 electrode4 18.5 electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode3 14.2 electrode3 14.8 electrode3 12.6 This is a simplified table XX electrode1 electrode2 electrode1 electrode3 electrode1 electrode4 electrode2 electrode1 electrode2 electrode3 electrode2 electrode4 electrode3 electrode1 electrode3 electrode2 electrode3 electrode4 electrode4 electrode1 electrode4 electrode2 electrode4 electrode3 Gesendet: Dienstag, 23. Juli 2013 um 13:36 Uhr Von: Rui Barradas ruipbarra...@sapo.pt An: dennis1...@gmx.net Cc: smartpink...@yahoo.com, 'r-help' r-help@r-project.org Betreff: Re: Aw: Re: [R] How to split two levels several times? Hello, It's better if you keep this on the list, the odds of getting more and better answers are greater. As for your new question, try the following. lens - rle(as.character(XXX$electrode))$lengths m - length(lens) %/% 2 idx - rep(1:m, sapply(1:m, function(.m) sum(lens[(2*.m - 1):(2*.m)]))) split(XXX, idx) Hope this helps, Rui Barradas Em 23-07-2013 11:41, dennis1...@gmx.net escreveu: Hi this type of splitting works for my specific example. Thanks for your help. I was not absolutely clear what I generally want. I'm looking for an option that generally permits splitting two joint levels of a table after each other. For instance for the table below I want it to be divided into combinations electrode1-electrode2, electrode3-electrode2, electrode4-electrode1. How should I split this? This is the table XXX electrode length electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode2 11.4 electrode2 9.7 electrode3 14.2 electrode3 14.8 electrode3 12.6 electrode2 11.4 electrode2 9.7 electrode4 17.0 electrode4 16.3 electrode4 17.8 electrode4 18.3
[R] Saved Session Pitfalls (was: ask help!)
On Thu, Jul 25, 2013 at 08:01:50PM +1000, Jim Lemon wrote: On 07/25/2013 07:44 PM, mei_yuan wrote: Hi, In the R console, I have the following: runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' Can someone advise me of the solution of the problem? Mei-Yuan Chen Hi Mei-Yuan, .Random.seed should be a vector of numeric values. Somehow this has been set to an object of type list: .Random.seed-list(.Random.seed) runif(10) Error in runif(10) : '.Random.seed' is not an integer vector but of type 'list' I would suggest quitting R and _not_ saving the session, then restarting and trying: runif(10) again. Not saving the session won't help if the previously saved session (still containing the broken .Random.seed) still lingers around. So the fix is to start a fresh R session without restoring the previous workspace (e.g. ``R --no-restore''), and then saving that. This will lose all previously created stuff, though (which is something to be aware of in case the workspace contains some precious unsaved data). Alternatively, if you run rm(.Random.seed) the ``runif(10)'' call will work again (and create a new .Random.seed of the right type as a side effect). Then when you quit, do save the workspace to fix the problem permanently. Generally, I recommend disabling automatic saving and restoring of workspaces, e.g. by aliasing R to ``R --no-save --no-restore'', and using the save and load functions explicitly where needed; I've seen (way too) many workspaces that have accumulated phenomenal amounts of clutter and generating quite a share of mysterious failures and irreproducibilities caused by this auto-save mechanism. Best regards, Jan -- +- Jan T. Kim ---+ | email: jtt...@gmail.com| | WWW: http://www.jtkim.dreamhosters.com/ | *-= hierarchical systems are for files, not for humans =-* __ 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] Function, that assigns two vectors to each other
Hello guys, I created an example data set: structure(list(pa = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), a1 = c(84, 108, 113, 99, 98, 88, 90, 89, 95, 77), a2 = c(113, 101, 99, 108, 122, 92, 90, 110, 109, 95), a3 = c(96, 108, 110, 99, 118, 100, 90, 89, 102, 99), a4 = c(76, 106, 94, 124, 91, 103, 107, 106, 113, 96)), .Names = c(pa, a1, a2, a3, a4), row.names = c(NA, -10L), class = data.frame) So the data frame contains the numbers of my participants (1 to 10) and the score, they hit on 4 tasks (a1 to a4). I wrote this function, to use on the data: pe-apply(X=my.data[,c(a1,a2,a3,a4)], MARGIN=2, FUN=quantile, probs=seq(0,1,by=.01), na.rm=TRUE) round(pe,0) It computes the percentiles of each task. So when using this function I know, that e.g. a person who got 77 points on task 1 (a1) has a percentile of 0%. If a person scores 88 points then he/she got the percentiles 21% to 27%, so 27% got the same amount of points or less. In comparison in task 4 (a4) a person reaching 77 points has a percentile of 1%. Now I want to add 4 columns to my.data (pe1 to pe4). The final data frame my.data shall have 10 rows and 9 columns These columns (pe1 to pe4) shall show the maximum percentile someone reached according to his points for each task. So for the person who reached 77 points in a1 the respective pe1 would be 0. For all the people who reached 88 points in a1 the respective pe1 would be 27. For all the people who reached 77 points in a4 the respective pe1 would be 1. The final data frame my.data shall have 10 rows and 9 columns. So for the first participant (pa=1), the pe's would be a1=84 -- pe=12; a2=113 -- pe=89, a3=96 -- pe=24, a4=76 -- pe=0 I hope, that is clearer than before :) Thanks a lot, Anne Am 24.07.2013 14:47, schrieb John Kane: Welcome to R-help it is a bit hard to see exactly what you want without data. Rest of the explanation looks good though it appears you may have sent this in HTML and the list asks for text. It strips out the html and we lose any html format. Can I suggest reading these https://github.com/hadley/devtools/wiki/Reproducibility http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and then getting back to use with some data. The best way to provide data , as is described in the above links is to use dput() (type ?dput for help ) and then just copy and paste the results into the mail. John Kane Kingston ON Canada -Original Message- From: gallr...@psychologie.tu-dresden.de Sent: Wed, 24 Jul 2013 12:25:35 +0200 To: r-help@r-project.org Subject: [R] Function, that assigns two vectors to each other Hey guys, In my data setv (KD) I have 4 columns (Punkte.AG1,Punkte.AG2,Punkte.AG3,Punkte.WI) I'm interested in. These columns contain the participants' scores of a specific task. I computed the percentiles of the columns using this code: pe-apply(X=KD[,c(Punkte.AG1,Punkte.AG2,Punkte.AG3,Punkte.WI)], MARGIN=2, FUN=quantile, probs=seq(0,1,by=.01), na.rm=TRUE) round(pe,0) This is the output (to the 20^th percentile): pe Punkte.AG1 Punkte.AG2 Punkte.AG3 Punkte.WI 0%6319 1%74311 2%86312 3%87412 4%97512 5%98512 6%108512 7%108512 8%108614 9%109614 10%109615 11%1010715 12%1010715 13%1110715 14%1110816 15%1110816 16%1110816 17%1110816 18%1110816 19%1210816 20%1210816 So now I know, what percentile a person has, when she/ he scored a certain amount of points (e.g. 6 points in Punkte.AG1 = 0%). Here is my problem: I now want to write a function that assigns the percentile to the score (for each task) and saves it in a new variable. So every person that scored 10 in Punkte.AG1 gets a 12 in the new variable Percentile.AG1. Every person that scored 6 in Punkte.AG1 gets a 6 in the new variable Percentile.AG1. The same thing should be done for the other tasks. I new to R, so I don't have any clue, how to solve that. It would be awesome, if you would know how to handle that. Thanks a lot! Anne -- M. Sc. Anne-Marie B. Gallrein Technische Universitdt Dresden Institut f|r Klinische, Diagnostische und Differentielle Psychologie Diagnostik und Intervention 01062 Dresden Tel. +49 351 463-34004 gallr...@psychologie.tu-dresden.de [[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. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk⢠and most webmails -- M. Sc. Anne-Marie B. Gallrein Technische
Re: [R] .eps files and powerpoint
Hi Duncan, Based upon the subsequent exchange with Rich late yesterday, I could not replicate the problem that he was having with lattice (OSX versus Windows), so I don't believe that this is germane any longer. I also used trellis.device() just as an alternative to calling postscript() directly and did not have any issues either. There is something else going on that has not become evident yet. Thanks, Marc On Jul 24, 2013, at 5:40 PM, Duncan Mackay mac...@northnet.com.au wrote: Hi Marc I sometimes had trouble with postscript and pdf files with lattice and I printed with trellis.device(device = pdf, ...) or trellis.device(device = postscript, ...) I wonder if this is the case here Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 03:22 25/07/2013, you wrote: Hi Rich, That's curious. I noted that you are using barchart() below which is lattice versus base graphics. Is there any difference in the result on Windows if you use barplot() instead? If so, perhaps there is something about lattice graphics in this context. Also, are you using Office 2008 or Office 2011 on your Mac? 2011 substantially improved Windows file format compatibility, not to mention a plethora of bug fixes. Regards, Marc On Jul 24, 2013, at 11:37 AM, Richard M. Heiberger r...@temple.edu wrote: Marc, very interesting. Your example works on Windows. This example doesn't work on windows postscript(file = file2.eps, height = 4, width = 4, + horizontal = FALSE, onefile = FALSE, paper = special) barchart(1:3) dev.off() Several examples, including the real one I was having trouble with previously, work on PowerPoint on Mac. They don't work on PowerPoint in Windows. More: I put some eps figures into PP on Mac (where they work) and then saved the file and opened it in PP on Windows. They don't work on Windows. Since Windows PP users are the target audience at the moment, I will stay with the res=300 png file. This is consistent with my other experiences with PP and Word for Mac, compared to PP and Word for Windows. The two MS sets of programs are highly correlated, but far from identical. When people send my PP or Word files, I am more likely to open them first on the Mac side of my machine. The graphs have spurious lines (connecting the end of the red line to the beginning of the green line, for example, when the two lines should be distinct). Alignment is different (two-line titles will get folded at the wrong place). I need to move back to the Windows side in the VM to see the files as the author intended. Rich On Wed, Jul 24, 2013 at 12:16 PM, Marc Schwartz marc_schwa...@me.comwrote: Hi Rich, Seems to work for me using Powerpoint in MS Office 2011 for Mac. I used the following code: postscript(file = file.eps, height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = special) plot(rnorm(20)) dev.off() Then I used the insert picture from file function in Powerpoint. It created the PNG preview during import and I can see that on the slide in the application without issue. I put the EPS file and the PPTX file up on DropBox if you want to look at them: EPS File: https://www.dropbox.com/s/d8avze4yv51blso/file.eps PPTX file: https://www.dropbox.com/s/pm7oejm0g6rc0a5/RPlot.pptx Regards, Marc On Jul 24, 2013, at 10:49 AM, Richard M. Heiberger r...@temple.edu wrote: Thanks Marc, the extra arguments to postscript still don't produce something that PowerPoint will accept. With your call, PP still displayed only the icon. PP did not generate its own png file. Since my immediate goal is the projection screen for a PowerPoint presentation, I will go directly to the png file. For the proceedings and for paper I will continue to use the pdf file. Rich On Wed, Jul 24, 2013 at 11:36 AM, Marc Schwartz marc_schwa...@me.comwrote: Rich, You are missing some options in the call to postscript() below. It needs to be: postscript(file = file.eps, width = x, height = y, horizontal = FALSE, onefile = FALSE, paper = special) The first line needs to have values for 'x' and 'y' for the width and height of the image, as they default to 0. The second line of 3 options are all critical to producing an EPS file, as opposed to a PS file. This is described in the 4th paragraph of the Details section of ?postscript. If you import that file into any of the MS Office products (typically also for OpenOffce, LibreOffice, etc.), a PNG preview image will be created during import. It is the PNG bitmapped image that you can see when displaying the EPS file in the document, hence the degradation in quality. Some years ago, all you
Re: [R] Levels of a factor
That makes sense. Thanks all! 2013/7/24 David Carlson dcarl...@tamu.edu Benchmark is probably a subset from a larger dataframe. R does not automatically remove empty levels but you can do it: set.seed(42) dataset - data.frame(Benchmark=factor(sample(LETTERS[1:26], 50, replace=TRUE), levels=LETTERS[1:26])) levels(dataset$Benchmark) # [1] A B C D E F G H I J K L M N O P Q R S # [20] T U V W X Y Z dataset$Benchmark - factor(dataset$Benchmark) levels(dataset$Benchmark) # [1] A C D F G H J K L M N O P Q R S T V X # [20] Y Z There are times when you want to know if certain factor levels do not appear in a subset of the original data. - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Borja Rivier Sent: Wednesday, July 24, 2013 8:25 AM To: r-help@r-project.org Subject: [R] Levels of a factor Hi all, I am having a bit of trouble using the levels() function. I have a factor with many elements, and when I use the function levels() to extract the list of unique elements, some of the elements returned are not actually in the factor. For example I would have this: vector - dataset$Benchmark class(vector) [1] factor length(vector) [1] 35615 vector2 - levels(vector) length(which(!(vector2 %in% vector))) [1] 235 Does anyone know how this is possible? Many thanks! Borja [[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.
[R] Computing standard error of the mean using REML
Let say we have different samples taken from the same population (I am talking about soil samples and different schemes of sampling) and now we want to compare the accuracy of samples using standard error of mean. I have been asked to compute standard error of the mean of samples using residual maximum likelihood (REML) however, I couldn't find any function in R to do it. All I could find were the function lmerTest that do maximum likelihood for the fixed effects modelling but not for computing the standard error of the mean. I would appreciate any clue. EJ [[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.
Re: [R] Saving multiple rda-files as one rda-file
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dark Sent: Thursday, July 25, 2013 11:00 AM To: r-help@r-project.org Subject: Re: [R] Saving multiple rda-files as one rda-file Really no one has any suggestions on this issue? What issue? AFAIK you can load any number of RDA files to your workspace and save your workspace as one file. I do not see any problem. Regards Petr -- View this message in context: http://r.789695.n4.nabble.com/Saving- multiple-rda-files-as-one-rda-file-tp4672041p4672278.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. __ 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] Computing standard error of the mean using REML
Dear Ebrahim, We do not deal with study or work assignments in this group. I'd suggest, nonetheless, to look into the lme4 package and the mer-class objects created with this package. Regards, José Prof. José Iparraguirre Chief Economist Age UK -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ebrahim Jahanshiri Sent: 25 July 2013 13:01 To: r-help@r-project.org Subject: [R] Computing standard error of the mean using REML Let say we have different samples taken from the same population (I am talking about soil samples and different schemes of sampling) and now we want to compare the accuracy of samples using standard error of mean. I have been asked to compute standard error of the mean of samples using residual maximum likelihood (REML) however, I couldn't find any function in R to do it. All I could find were the function lmerTest that do maximum likelihood for the fixed effects modelling but not for computing the standard error of the mean. I would appreciate any clue. EJ [[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. The Wireless from Age UK | Radio for grown-ups. www.ageuk.org.uk/thewireless If you’re looking for a radio station that offers real variety, tune in to The Wireless from Age UK. Whether you choose to listen through the website at www.ageuk.org.uk/thewireless, on digital radio (currently available in London and Yorkshire) or through our TuneIn Radio app, you can look forward to an inspiring mix of music, conversation and useful information 24 hours a day. --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] [R-pkgs] WriteXLS Version 3.0.0 Released
Hi, Perl is still required for WriteXLS. That dependency has not changed. What did change is that I removed the requirement for Text::CSV_XS, which contains C code in the Perl package source that required compilation and therefore could not be included in the WriteXLS CRAN package. The compilation process to create the binary is OS and Perl version specific. Thus, if not already installed, WriteXLS users would either have to install a pre-compiled binary using their Perl or OS package manager or via the CLI using 'cpan' and compile during local installation, which requires that compiler related tools also be installed, making it a bit more cumbersome. I can now include Text::CSV_PP, which is recently stable enough to use and is a Perl only implementation of the CSV file parsing functionality found in Text::CSV_XS. The output below suggests that you have Perl version 5.14 installed but that you may be missing Archive::Zip, which based upon my prior research is typically installed with most recent Perl distributions. Thus, I did not include it in the WriteXLS CRAN package nor do I check for it in testPerl(). Archive::Zip is a dependency for Excel::Writer::XLSX, which creates the XLSX files in WriteXLS(). Can you run testPerl() from the WriteXLS package and post back the output and also let me know what OS you are running? I presume some Linux distribution, albeit feedback from others using the new version of WriteXLS on Linux, OSX and Windows have not indicated that Archive::Zip is missing. I may then need to update WriteXLS to include Archive::Zip if there are some Perl installations that do not include it. Thanks, Marc On Jul 24, 2013, at 11:24 PM, Orvalho Augusto orvaq...@gmail.com wrote: Hello! None can imagine how this package is helpful for me. I might have understood wrong... is it correct that WriteXLS doesn't no more require Perl? It is because I got this on my machine: WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE, BoldHeaderRow = TRUE) Can't locate Archive/Zip.pm in @INC (@INC contains: /usr/local/lib/R/site-library/WriteXLS/Perl /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. The Perl script 'WriteXLSX.pl' failed to run successfully. Thank you Caveman On Wed, Jul 24, 2013 at 2:27 PM, Marc Schwartz marc_schwa...@me.com wrote: On Jul 23, 2013, at 5:40 PM, cognizio ge...@uyleman.com wrote: Great summary! It works great without the heavy PERL library. I am running the YAML package I thought I needed to support WRITEXLS. Do I need it or is YAML not a dependency? Other question is on your last point: 'WRITEXLS COMMENT:' now shows up across the first row of the data output in the XLS. How do I modify these values? Thx! Cog Hi, There is no direct dependency on YAML. The comments that appear in the first row in Excel are based upon the use of the ?comment function, which adds a 'comment' attribute to the columns of the data frame. If that attribute is present on one or more columns, an Excel comment will be created for the columns that have it. There is an example of this in ?WriteXLS: # Example using comment() # Commented cells with have a small red triangle in the # upper right hand corner of the cell. Click on the cell # or place the cursor over the cell to see the pop-up # containing the comment text. # Create an XLSX (Excel 2007) file # Adjust the column widths # Bold the header row comment(iris$Sepal.Length) - Length of the sepals (cm) comment(iris$Sepal.Width) - Width of the sepals (cm) comment(iris$Petal.Length) - Length of the petals (cm) comment(iris$Petal.Width) - Width of the petals (cm) comment(iris$Species) - Species of the flowers WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE, BoldHeaderRow = TRUE) The 'comment' attribute is not seen when printing the data frame, but can be seen when using ?str to print the structure of the data frame: str(iris) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: atomic 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... ..- attr(*, comment)= chr Length of the sepals (cm) $ Sepal.Width : atomic 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... ..-
Re: [R] .eps files and powerpoint
your eps file appears as an icon in powerpoint 2010 and 2013 on windows 7 in my VM. the same file opens as a proper graph on powerpoint 2011 in Mac. On Wed, Jul 24, 2013 at 12:16 PM, Marc Schwartz marc_schwa...@me.comwrote: Hi Rich, Seems to work for me using Powerpoint in MS Office 2011 for Mac. I used the following code: postscript(file = file.eps, height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = special) plot(rnorm(20)) dev.off() Then I used the insert picture from file function in Powerpoint. It created the PNG preview during import and I can see that on the slide in the application without issue. I put the EPS file and the PPTX file up on DropBox if you want to look at them: EPS File: https://www.dropbox.com/s/d8avze4yv51blso/file.eps PPTX file: https://www.dropbox.com/s/pm7oejm0g6rc0a5/RPlot.pptx Regards, Marc On Jul 24, 2013, at 10:49 AM, Richard M. Heiberger r...@temple.edu wrote: Thanks Marc, the extra arguments to postscript still don't produce something that PowerPoint will accept. With your call, PP still displayed only the icon. PP did not generate its own png file. Since my immediate goal is the projection screen for a PowerPoint presentation, I will go directly to the png file. For the proceedings and for paper I will continue to use the pdf file. Rich On Wed, Jul 24, 2013 at 11:36 AM, Marc Schwartz marc_schwa...@me.comwrote: Rich, You are missing some options in the call to postscript() below. It needs to be: postscript(file = file.eps, width = x, height = y, horizontal = FALSE, onefile = FALSE, paper = special) The first line needs to have values for 'x' and 'y' for the width and height of the image, as they default to 0. The second line of 3 options are all critical to producing an EPS file, as opposed to a PS file. This is described in the 4th paragraph of the Details section of ?postscript. If you import that file into any of the MS Office products (typically also for OpenOffce, LibreOffice, etc.), a PNG preview image will be created during import. It is the PNG bitmapped image that you can see when displaying the EPS file in the document, hence the degradation in quality. Some years ago, all you would see is a rectangular box with an X across it, as a placeholder for the imported image. Only if you then print the Office file using a Postscript printer driver, will you see the actual vector based EPS image. The target of that printing operation could be a printer for hard copy, a PS or a PDF file. MS Office does not support the rendering of the EPS image directly. If you are operating on Windows, as opposed to Linux or OSX, typically EMF/WMF files are the easiest way to go in terms of sticking R plots into an Office file, as they are also vector based images, but are effectively Windows only. Regards, Marc Schwartz On Jul 24, 2013, at 10:20 AM, Richard M. Heiberger r...@temple.edu wrote: png(png300.png, res=300, width=2880, height=1440) gives good behavior. Thank you. This will become my standard for export to powerpoint. postscript(file='file.eps', onefile=FALSE) produces eps files that powerpoint rejects, even though ghostview is satisfied. Rich On Wed, Jul 24, 2013 at 2:07 AM, Patrick Connolly p_conno...@slingshot.co.nz wrote: On Tue, 23-Jul-2013 at 10:23PM -0400, Richard M. Heiberger wrote: | I have colleagues who use powerpoint. When I send my colleagues pdf files | or ps files, powerpoint | rejects them. Powerpoint does accept some eps files. | [...] | Does anyone know a workaround that will get vector graphics from R into | powerpoint? | win.metafile is not acceptable. The resolution of emf files from R is | worse than png files. Maybe worse than png files at the default resolution which is 72 dpi. Change that to something like 300 and nobody will see a jagged edge in a PowerPoint slide. HTH | | Thanks | Rich [[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.
Re: [R] .eps files and powerpoint
file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.com wrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich Sent from my iPhone On Jul 24, 2013, at 13:22, Marc Schwartz marc_schwa...@me.com wrote: Hi Rich, That's curious. I noted that you are using barchart() below which is lattice versus base graphics. Is there any difference in the result on Windows if you use barplot() instead? If so, perhaps there is something about lattice graphics in this context. Also, are you using Office 2008 or Office 2011 on your Mac? 2011 substantially improved Windows file format compatibility, not to mention a plethora of bug fixes. Regards, Marc On Jul 24, 2013, at 11:37 AM, Richard M. Heiberger r...@temple.edu wrote: Marc, very interesting. Your example works on Windows. This example doesn't work on windows postscript(file = file2.eps, height = 4, width = 4, + horizontal = FALSE, onefile = FALSE, paper = special) barchart(1:3) dev.off() Several examples, including the real one I was having trouble with previously, work on PowerPoint on Mac. They don't work on PowerPoint in Windows. More: I put some eps figures into PP on Mac (where they work) and then saved the file and opened it in PP on Windows. They don't work on Windows. Since Windows PP users are the target audience at the moment, I will stay with the res=300 png file. This is consistent with my other experiences with PP and Word for Mac, compared to PP and Word for Windows. The two MS sets of programs are highly correlated, but far from identical. When people send my PP or Word files, I am more likely to open them first on the Mac side of my machine. The graphs have spurious lines (connecting the end of the red line to the beginning of the green line, for example, when the two lines should be distinct). Alignment is different (two-line titles will get folded at the wrong place). I need to move back to the Windows side in the VM to see the files as the author intended. Rich On Wed, Jul 24, 2013 at 12:16 PM, Marc Schwartz marc_schwa...@me.com wrote: Hi Rich, Seems to work for me using Powerpoint in MS Office 2011 for Mac. I used the following code: postscript(file = file.eps, height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = special) plot(rnorm(20)) dev.off() Then I used the insert picture from file function in Powerpoint. It created the PNG preview during import and I can see that on the slide in the application without issue. I put the EPS file and the PPTX file up on DropBox if you want to look at them: EPS File: https://www.dropbox.com/s/d8avze4yv51blso/file.eps PPTX file: https://www.dropbox.com/s/pm7oejm0g6rc0a5/RPlot.pptx Regards, Marc On Jul 24, 2013, at 10:49 AM, Richard M. Heiberger r...@temple.edu wrote: Thanks Marc, the extra arguments to postscript still don't produce something that PowerPoint will accept. With your call, PP still displayed only the icon. PP did not generate its own png file. Since my immediate goal is the projection screen for a PowerPoint presentation, I will go directly to the png file. For the proceedings and for paper I will continue to use the pdf file. Rich On Wed, Jul 24, 2013 at 11:36 AM, Marc Schwartz marc_schwa...@me.com wrote: Rich, You are missing some options in the call to postscript() below. It needs to be: postscript(file = file.eps, width = x, height = y, horizontal = FALSE, onefile = FALSE, paper = special) The first line needs to have values for 'x' and 'y' for the width and height of the image, as they default to 0. The second line of 3 options are all critical
Re: [R] .eps files and powerpoint
The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.eduwrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.comwrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich Sent from my iPhone On Jul 24, 2013, at 13:22, Marc Schwartz marc_schwa...@me.com wrote: Hi Rich, That's curious. I noted that you are using barchart() below which is lattice versus base graphics. Is there any difference in the result on Windows if you use barplot() instead? If so, perhaps there is something about lattice graphics in this context. Also, are you using Office 2008 or Office 2011 on your Mac? 2011 substantially improved Windows file format compatibility, not to mention a plethora of bug fixes. Regards, Marc On Jul 24, 2013, at 11:37 AM, Richard M. Heiberger r...@temple.edu wrote: Marc, very interesting. Your example works on Windows. This example doesn't work on windows postscript(file = file2.eps, height = 4, width = 4, + horizontal = FALSE, onefile = FALSE, paper = special) barchart(1:3) dev.off() Several examples, including the real one I was having trouble with previously, work on PowerPoint on Mac. They don't work on PowerPoint in Windows. More: I put some eps figures into PP on Mac (where they work) and then saved the file and opened it in PP on Windows. They don't work on Windows. Since Windows PP users are the target audience at the moment, I will stay with the res=300 png file. This is consistent with my other experiences with PP and Word for Mac, compared to PP and Word for Windows. The two MS sets of programs are highly correlated, but far from identical. When people send my PP or Word files, I am more likely to open them first on the Mac side of my machine. The graphs have spurious lines (connecting the end of the red line to the beginning of the green line, for example, when the two lines should be distinct). Alignment is different (two-line titles will get folded at the wrong place). I need to move back to the Windows side in the VM to see the files as the author intended. Rich On Wed, Jul 24, 2013 at 12:16 PM, Marc Schwartz marc_schwa...@me.com wrote: Hi Rich, Seems to work for me using Powerpoint in MS Office 2011 for Mac. I used the following code: postscript(file = file.eps, height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = special) plot(rnorm(20)) dev.off() Then I used the insert picture from file function in Powerpoint. It created the PNG preview during import and I can see that on the slide in the application without issue. I put the EPS file and the PPTX file up on DropBox if you want to look at them: EPS File: https://www.dropbox.com/s/d8avze4yv51blso/file.eps PPTX file: https://www.dropbox.com/s/pm7oejm0g6rc0a5/RPlot.pptx Regards, Marc On Jul 24, 2013, at 10:49 AM, Richard M. Heiberger r...@temple.edu wrote: Thanks Marc, the extra arguments to postscript still don't produce something that PowerPoint will accept. With your call, PP still displayed only the icon. PP did not generate its own png file. Since my immediate goal is the projection screen for a PowerPoint presentation, I will go directly to the png file. For the proceedings and for paper I will continue to use the pdf file. Rich On Wed, Jul 24, 2013 at 11:36 AM, Marc Schwartz marc_schwa...@me.comwrote: Rich, You are missing some options in the call to postscript() below. It needs to be: postscript(file = file.eps, width = x, height = y, horizontal = FALSE, onefile = FALSE, paper = special) The first
[R] Network of cities with distances as edges length
Hello, I am building a network using a distance matrix with the package 'network' I want to create a network with cities as vertices and with the length of the edges between them that reflects their distances. How can I ? All I tried did not work I tried the following code but the result is a graph with curved edges that do not reflect distances between cities. It is not what I want. nDist2 = network(Dist2,directed=TRUE) set.edge.value(nDist2,'Km',Dist2) plot.network(nDist2,label=network.vertex.names(nDist2), edge.len=get.edge.value(nDist2,'Km')/1,uselen=T) My data matrix (Dist2) is: Oxford Hamburg Dublin Hoersholm Oslo Oxford 0 786.4 382.97 1013.98 1176.23 Hamburg 786.4 0 1077.74 305.9 710.03 Dublin 382.97 1077.74 0 1240.48 1268.59 Hoersholm 1013.98 305.9 1240.48 0 460.72 Oslo 1176.23 710.03 1268.59 460.72 0 Thanks Edoardo [[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.
Re: [R] Unable to install packages
I'd start with the home page for R: http://www.r-project.org/ because you seem to have no idea what version is current (3.0.1). You will find Google to be very helpful. As for manuals, the official documentation is at http://cran.r-project.org/manuals.html and the user contributed manuals are at http://cran.r-project.org/other-docs.html which includes R and Data Mining: Examples and Case Studies by Yanchang Zhao (PDF, 2013-04-26, 160 pages). the Task Views are at http://cran.r-project.org/web/views/ There are a number of other useful web sites including http://www.statmethods.net/index.html http://www.ats.ucla.edu/stat/r/ http://www.cyclismo.org/tutorial/R/ http://ww2.coastal.edu/kingw/statistics/R-tutorials/ Just to get you started. - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Arnab Chakrabarti Sent: Thursday, July 25, 2013 2:36 AM To: r-help@r-project.org Subject: [R] Unable to install packages Hi all. I am new to R. I have just installed R2.10.1 for my Windows 7 computer. When I go to Packages Install Packages on the drop-down list, I get the message: Warning: unable to access index for repository http://ftp.iitm.ac.in/cran/bin/windows/contrib/2.10 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10 Error in install.packages (Null, .libPaths () [1L], dependencies = NA, type = type) : no packages were specified Please advise suitably. Also suggest any good free online book/free online recognized course to * quickly* master R for data mining. [[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. __ 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] .eps files and powerpoint
Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.eduwrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.comwrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content __ 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] .eps files and powerpoint
i have parallels 8 as the vm. i can try a native pc this afternoon. Sent from my iPhone On Jul 25, 2013, at 10:42, Marc Schwartz marc_schwa...@me.com wrote: Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.eduwrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.comwrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content __ 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] transform dataframe with look-up table
Hello I hope that there is a simple solution to this apparently complex problem. Any help will be much appreciated: I have a dataframe with Left and Right readings (that is, elements in each row are paired). For instance, Left Right [1] 98 [2] 43 [3] 21 [4] 65 [5] 31 [6] 41 [7] 32 [8] 42 [9] 10 8 [10] 9 10 I need to produce a new data frame where the values are transformed according to a look-up table such as inputoutput [1] 5 1 [2]10 1 [3] 4 2 [4] 8 3 [5] 6 5 [6] 5 6 [7] 7 6 [8] 2 7 [9] 9 7 [10]107 [11] 2 8 So [1, ] in the new dataframe would be 7 3. Quite simple so far, but what makes things complicated is the multiple outputs for a single input. In this example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must yield two rows in its output counterpart: 1 3 and 7 3. Likewise the output for [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are missing as inputs the output for [5, ] should be NA NA. Thank you very much for your time. Juan Antonio Balbuena -- Dr. Juan A. Balbuena Marine Zoology Unit Cavanilles Institute of Biodiversity and Evolutionary Biology University of Valencia [1]http://www.uv.es/~balbuena P.O. Box 22085 [2]http://www.uv.es/cavanilles/zoomarin/index.htm 46071 Valencia, Spain [3]http://cetus.uv.es/mullpardb/index.html e-mail: [4]j.a.balbu...@uv.estel. +34 963 543 658fax +34 963 543 733 NOTE! For shipments by EXPRESS COURIER use the following street address: C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain. References 1. http://www.uv.es/%7Ebalbuena 2. http://www.uv.es/cavanilles/zoomarin/index.htm 3. http://cetus.uv.es/mullpardb/index.html 4. mailto:j.a.balbu...@uv.es __ 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] x-axis (categorial variable) ordering with xyplot function (lattice package)
Dear Duncan, If you want to make a plot of the style of xyplot a numerical index of the country is needed and then use the scales argument to annote the labels with the country. I think you were right. It worked and I does seem to be the simplest option. Many thanks ! Regards, Arnaud Le 25.07.2013 00:41, Duncan Mackay a écrit : forgot to cc to list Hi For an xyplot you have not got the proper coding for the x value which should be numeric. If you want to make a plot of the style of xyplot a numerical index of the country is needed and then use the scales argument to annote the labels with the country. Do you want multiple panels ? A self contained dataset via dput would help elicit further information. Have a look at the outer and related arguments as well as the group arguments. A combined index for regions with countries may be necessary. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 00:17 25/07/2013, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2322 Dear R mailing list readers, I am facing the following problem; for simplicity imagine I am working on a data frame of, say, 5 columns. The first column is a list of European countries, the other four are an index (continuous variable) of climate change impact under 4 different scenarios. Country 2050B2 2050A2 2080B2 2080A2 Austria -0.2 -0.6 ... Belgium -0.2 -0.6 Bulgaria -0.5 -0.8 Czech republic -0.5 -0.8 United kingdom -0.2 -0.6 I am using the package lattice to make a nice plot of the dots from the different scenario using the following code; my.plot - xyplot(2050B2+2050A2+2080B2+2080A2~country, data=my.dat, scales=list(x=list(rot=45))) note: the part scales=list(x=list(rot=45)) is pure aesthetic here. So far, so good. However, I wish to order the x-axis (countries) by grouping them by European region; i.e Austria, Belgium and United kingdom are western Europe, while Bulgaria and Czech republic are eastern Europe. In excel I added a new region) variable (i.e 1 for Western Europe, 2 for eastern Europe) and I re-ordered my data frame according to this region variable. I then imported this updated data frame in R, and checked how it looked with the usual code; pot_dat -read.csv(file.choose(),header=TRUE, sep=;,dec=.) pot_dat Again, so far so good; my second column (country) is now ordered according to the values of the first column (region). Region Country 2050B2 2050A2 2080B2 2080A2 1 Austria -0.2 -0.6 ... 1 Belgium -0.2 -0.6 1 United Kingdom -0.2 -0.6 2 Bulgaria -0.5 -0.8 2 Czech republic -0.5 -0.8 However, when I try to use the code as above, R automatically re-order the x-axis (country) in alphabetical order. This was not unexpected, but I have spent the day (unsuccessfully) looking for a way to simply tell R not to do that and to keep the variable country as it is now ordered in the data frame to construct the x-axis of my plot. Is there any way to force it to keep the order as it is in the data frame ? Any help would be really welcomed ! Best, Arnaud Blaser PhD candidate University of Neuchâtel Institute of Economic Research (IRENE) Pierre-à-Mazel 7 CH-2000 Neuchâtel [[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. __ 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. -- -- Arnaud Blaser PhD candidate University of Neuchâtel Institute of Economic Research (IRENE) Pierre-à-Mazel 7 CH-2000 Neuchâtel __ 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] [R-pkgs] WriteXLS Version 3.0.0 Released
Thank you for the feedback. I installed the missing Archive::Zip packge and everthing went fine. Orvalho On Thu, Jul 25, 2013 at 3:00 PM, Marc Schwartz marc_schwa...@me.com wrote: Hi, Perl is still required for WriteXLS. That dependency has not changed. What did change is that I removed the requirement for Text::CSV_XS, which contains C code in the Perl package source that required compilation and therefore could not be included in the WriteXLS CRAN package. The compilation process to create the binary is OS and Perl version specific. Thus, if not already installed, WriteXLS users would either have to install a pre-compiled binary using their Perl or OS package manager or via the CLI using 'cpan' and compile during local installation, which requires that compiler related tools also be installed, making it a bit more cumbersome. I can now include Text::CSV_PP, which is recently stable enough to use and is a Perl only implementation of the CSV file parsing functionality found in Text::CSV_XS. The output below suggests that you have Perl version 5.14 installed but that you may be missing Archive::Zip, which based upon my prior research is typically installed with most recent Perl distributions. Thus, I did not include it in the WriteXLS CRAN package nor do I check for it in testPerl(). Archive::Zip is a dependency for Excel::Writer::XLSX, which creates the XLSX files in WriteXLS(). Can you run testPerl() from the WriteXLS package and post back the output and also let me know what OS you are running? I presume some Linux distribution, albeit feedback from others using the new version of WriteXLS on Linux, OSX and Windows have not indicated that Archive::Zip is missing. I may then need to update WriteXLS to include Archive::Zip if there are some Perl installations that do not include it. Thanks, Marc On Jul 24, 2013, at 11:24 PM, Orvalho Augusto orvaq...@gmail.com wrote: Hello! None can imagine how this package is helpful for me. I might have understood wrong... is it correct that WriteXLS doesn't no more require Perl? It is because I got this on my machine: WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE, BoldHeaderRow = TRUE) Can't locate Archive/Zip.pm in @INC (@INC contains: /usr/local/lib/R/site-library/WriteXLS/Perl /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. The Perl script 'WriteXLSX.pl' failed to run successfully. Thank you Caveman On Wed, Jul 24, 2013 at 2:27 PM, Marc Schwartz marc_schwa...@me.com wrote: On Jul 23, 2013, at 5:40 PM, cognizio ge...@uyleman.com wrote: Great summary! It works great without the heavy PERL library. I am running the YAML package I thought I needed to support WRITEXLS. Do I need it or is YAML not a dependency? Other question is on your last point: 'WRITEXLS COMMENT:' now shows up across the first row of the data output in the XLS. How do I modify these values? Thx! Cog Hi, There is no direct dependency on YAML. The comments that appear in the first row in Excel are based upon the use of the ?comment function, which adds a 'comment' attribute to the columns of the data frame. If that attribute is present on one or more columns, an Excel comment will be created for the columns that have it. There is an example of this in ?WriteXLS: # Example using comment() # Commented cells with have a small red triangle in the # upper right hand corner of the cell. Click on the cell # or place the cursor over the cell to see the pop-up # containing the comment text. # Create an XLSX (Excel 2007) file # Adjust the column widths # Bold the header row comment(iris$Sepal.Length) - Length of the sepals (cm) comment(iris$Sepal.Width) - Width of the sepals (cm) comment(iris$Petal.Length) - Length of the petals (cm) comment(iris$Petal.Width) - Width of the petals (cm) comment(iris$Species) - Species of the flowers WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE, BoldHeaderRow = TRUE) The 'comment' attribute is not seen when printing the data frame, but can be seen when using ?str to print the structure
Re: [R] SpatialPolygonsDataFrame and unique()
Nicola Rossi nicola.rossi20 at gmail.com writes: Hello everyone! I'm a newbie in using the RGDAL and sp packages in R and as written in the object I have a problem with a SPDF and unique(): Consider posting to the R-sig-geo list; this is not a general R question. I would have liked to write a simple script to delete in a couple of clicks the duplicated nodes that sometimes pop-up during the digitizing process in QGIS (I know that this can be done by hand, but when you have lots of features using a script in R would save some time). Have you actually thought through what you are doing in the light of the fact that Polygon objects are defined as having coords slots Object of class matrix; coordinates of the polygon; first point should equal the last point in ?Polygon-class? You are choosing the 2:n-1 rows of this matrix, so removing the end points which must by definition be identical. So for an arbitrary SpatialPolygons object, you see: validObject(slot(slot(spatial, polygons)[[1]], Polygons)[[1]]) Error in validObject(slot(slot(spatial, polygons)[[1]], Polygons)[[1]]) : invalid class “Polygon” object: ring not closed There are lots of other infelicities in your script, which uses the internal @ operator - never do this, always use access functions, lapply(), and class-based constructors to ensure that the related internal objects get updated. With your coding choices, none of the automatic mechanisms checking validity get invoked. You would need to reconstruct the coords matrix by retaining the first and last rows, and using unique only on rows 2:n-1, using rbind(), then pass this through Polygon() and Polygons() to recreate the internal representations. Hope this clarifies, Roger I tried to use unique() in the coords slot, but it simply doesn't work and I can't figure out why. here's a copy of the script that I wrote: library(rgdal) p4s-+proj=tmerc +lat_0=0 +lon_0=21 +k=1 +x_0=150 +y_0=0 +ellps=intl +units=m +no_defs layer-c(Kataja) dsn-c(C:/Users/vagabond/Desktop/copy_for_r) spatial-readOGR(dsn=dsn,layer=layer,p4s=p4s) len-length(spatial) for (i in 1:len){ + temp-length(spatial at polygons[[i]] at Polygons[[1]] at coords[,1])-1 + spatial at polygons[[i]] at Polygons[[1]] at coords-unique(spatial at polygons [[i]] at Polygons[[1]] at coords[2:temp,]) + } Thank you very much for the help! Nicola Please never post HTML! [[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.
Re: [R] [R-pkgs] WriteXLS Version 3.0.0 Released
Hi, Thank you. I will work on an update to the package that includes Archive::Zip so that it covers this situation. Regards. Marc On Jul 25, 2013, at 10:30 AM, Orvalho Augusto orvaq...@gmail.com wrote: Thank you for the feedback. I installed the missing Archive::Zip packge and everthing went fine. Orvalho On Thu, Jul 25, 2013 at 3:00 PM, Marc Schwartz marc_schwa...@me.com wrote: Hi, Perl is still required for WriteXLS. That dependency has not changed. What did change is that I removed the requirement for Text::CSV_XS, which contains C code in the Perl package source that required compilation and therefore could not be included in the WriteXLS CRAN package. The compilation process to create the binary is OS and Perl version specific. Thus, if not already installed, WriteXLS users would either have to install a pre-compiled binary using their Perl or OS package manager or via the CLI using 'cpan' and compile during local installation, which requires that compiler related tools also be installed, making it a bit more cumbersome. I can now include Text::CSV_PP, which is recently stable enough to use and is a Perl only implementation of the CSV file parsing functionality found in Text::CSV_XS. The output below suggests that you have Perl version 5.14 installed but that you may be missing Archive::Zip, which based upon my prior research is typically installed with most recent Perl distributions. Thus, I did not include it in the WriteXLS CRAN package nor do I check for it in testPerl(). Archive::Zip is a dependency for Excel::Writer::XLSX, which creates the XLSX files in WriteXLS(). Can you run testPerl() from the WriteXLS package and post back the output and also let me know what OS you are running? I presume some Linux distribution, albeit feedback from others using the new version of WriteXLS on Linux, OSX and Windows have not indicated that Archive::Zip is missing. I may then need to update WriteXLS to include Archive::Zip if there are some Perl installations that do not include it. Thanks, Marc On Jul 24, 2013, at 11:24 PM, Orvalho Augusto orvaq...@gmail.com wrote: Hello! None can imagine how this package is helpful for me. I might have understood wrong... is it correct that WriteXLS doesn't no more require Perl? It is because I got this on my machine: WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE, BoldHeaderRow = TRUE) Can't locate Archive/Zip.pm in @INC (@INC contains: /usr/local/lib/R/site-library/WriteXLS/Perl /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX/Workbook.pm line 25. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/Excel/Writer/XLSX.pm line 18. Compilation failed in require at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. BEGIN failed--compilation aborted at /usr/local/lib/R/site-library/WriteXLS/Perl/WriteXLSX.pl line 35. The Perl script 'WriteXLSX.pl' failed to run successfully. Thank you Caveman On Wed, Jul 24, 2013 at 2:27 PM, Marc Schwartz marc_schwa...@me.com wrote: On Jul 23, 2013, at 5:40 PM, cognizio ge...@uyleman.com wrote: Great summary! It works great without the heavy PERL library. I am running the YAML package I thought I needed to support WRITEXLS. Do I need it or is YAML not a dependency? Other question is on your last point: 'WRITEXLS COMMENT:' now shows up across the first row of the data output in the XLS. How do I modify these values? Thx! Cog Hi, There is no direct dependency on YAML. The comments that appear in the first row in Excel are based upon the use of the ?comment function, which adds a 'comment' attribute to the columns of the data frame. If that attribute is present on one or more columns, an Excel comment will be created for the columns that have it. There is an example of this in ?WriteXLS: # Example using comment() # Commented cells with have a small red triangle in the # upper right hand corner of the cell. Click on the cell # or place the cursor over the cell to see the pop-up # containing the comment text. # Create an XLSX (Excel 2007) file # Adjust the column widths # Bold the header row comment(iris$Sepal.Length) - Length of the sepals (cm) comment(iris$Sepal.Width) - Width of the sepals (cm) comment(iris$Petal.Length) - Length of the petals (cm) comment(iris$Petal.Width) - Width of the petals (cm) comment(iris$Species) - Species of the flowers WriteXLS(iris, iriscomments.xlsx, AdjWidth = TRUE,
Re: [R] transform dataframe with look-up table
Perhaps this will help. Jean df - structure(list(Left = c(9L, 4L, 2L, 6L, 3L, 4L, 3L, 4L, 10L, 9L), Right = c(8L, 3L, 1L, 5L, 1L, 1L, 2L, 2L, 8L, 10L)), .Names = c(Left, Right), class = data.frame, row.names = 1:10) lookup - structure(list(input = c(5L, 10L, 4L, 8L, 6L, 5L, 7L, 2L, 9L, 10L, 2L), output = c(1L, 1L, 2L, 3L, 5L, 6L, 6L, 7L, 7L, 7L, 8L)), .Names = c(input, output), class = data.frame, row.names = 1:10) df2 - merge(df, lookup, by.x=Left, by.y=input, all.x=TRUE) names(df2)[names(df2)==output] - Leftout df3 - merge(df2, lookup, by.x=Right, by.y=input, all.x=TRUE) names(df3)[names(df3)==output] - Rightout Right Left Leftout Rightout 1 12 7 NA 2 12 8 NA 3 13 NA NA 4 14 2 NA 5 23 NA7 6 23 NA8 7 24 27 8 24 28 9 34 2 NA 10 56 56 11 56 51 12 89 73 13 8 10 13 14 8 10 73 15109 71 16109 77 On Thu, Jul 25, 2013 at 10:13 AM, Juan Antonio Balbuena j.a.balbu...@uv.eswrote: Hello I hope that there is a simple solution to this apparently complex problem. Any help will be much appreciated: I have a dataframe with Left and Right readings (that is, elements in each row are paired). For instance, Left Right [1] 98 [2] 43 [3] 21 [4] 65 [5] 31 [6] 41 [7] 32 [8] 42 [9] 10 8 [10] 9 10 I need to produce a new data frame where the values are transformed according to a look-up table such as inputoutput [1] 5 1 [2]10 1 [3] 4 2 [4] 8 3 [5] 6 5 [6] 5 6 [7] 7 6 [8] 2 7 [9] 9 7 [10]107 [11] 2 8 So [1, ] in the new dataframe would be 7 3. Quite simple so far, but what makes things complicated is the multiple outputs for a single input. In this example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must yield two rows in its output counterpart: 1 3 and 7 3. Likewise the output for [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are missing as inputs the output for [5, ] should be NA NA. Thank you very much for your time. Juan Antonio Balbuena -- Dr. Juan A. Balbuena Marine Zoology Unit Cavanilles Institute of Biodiversity and Evolutionary Biology University of Valencia [1]http://www.uv.es/~balbuena P.O. Box 22085 [2]http://www.uv.es/cavanilles/zoomarin/index.htm 46071 Valencia, Spain [3]http://cetus.uv.es/mullpardb/index.html e-mail: [4]j.a.balbu...@uv.estel. +34 963 543 658fax +34 963 543 733 NOTE! For shipments by EXPRESS COURIER use the following street address: C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain. References 1. http://www.uv.es/%7Ebalbuena 2. http://www.uv.es/cavanilles/zoomarin/index.htm 3. http://cetus.uv.es/mullpardb/index.html 4. mailto:j.a.balbu...@uv.es __ 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.
Re: [R] transform dataframe with look-up table
It would be helpful if you included the expected output for your example, but I think the following does what you want by using merge() for each lookup: f0 - function(inputDF, lookupDF) { tmp1 - merge(inputDF, lookupDF, by.x=Left, by.y=input,all.x=TRUE) tmp2 - merge(tmp1, lookupDF, by.x=Right, by.y=input, all.x=TRUE) with(tmp2, data.frame(ID=ID, Right=output.x, Left=output.y)[order(ID), ]) } # Your example data with an ID column added to track where the output rows came from myInputDF - data.frame( ID = 1:10, Left = c(9, 4, 2, 6, 3, 4, 3, 4, 10, 9), Right = c(8, 3, 1, 5, 1, 1, 2, 2, 8, 10)) myLookupDF - data.frame( input = c(5, 10, 4, 8, 6, 5, 7, 2, 9, 10, 2), output = c(1, 1, 2, 3, 5, 6, 6, 7, 7, 7, 8)) f0(myInputDF, myLookupDF) #ID Right Left # 12 1 73 # 9 2 2 NA # 1 3 7 NA # 2 3 8 NA # 10 4 56 # 11 4 51 # 3 5NA NA # 4 6 2 NA # 5 7NA7 # 6 7NA8 # 7 8 27 # 8 8 28 # 13 9 13 # 14 9 73 # 15 10 71 # 16 10 77 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Juan Antonio Balbuena Sent: Thursday, July 25, 2013 8:13 AM To: r-help@r-project.org Subject: [R] transform dataframe with look-up table Hello I hope that there is a simple solution to this apparently complex problem. Any help will be much appreciated: I have a dataframe with Left and Right readings (that is, elements in each row are paired). For instance, Left Right [1] 98 [2] 43 [3] 21 [4] 65 [5] 31 [6] 41 [7] 32 [8] 42 [9] 10 8 [10] 9 10 I need to produce a new data frame where the values are transformed according to a look-up table such as inputoutput [1] 5 1 [2]10 1 [3] 4 2 [4] 8 3 [5] 6 5 [6] 5 6 [7] 7 6 [8] 2 7 [9] 9 7 [10]107 [11] 2 8 So [1, ] in the new dataframe would be 7 3. Quite simple so far, but what makes things complicated is the multiple outputs for a single input. In this example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must yield two rows in its output counterpart: 1 3 and 7 3. Likewise the output for [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are missing as inputs the output for [5, ] should be NA NA. Thank you very much for your time. Juan Antonio Balbuena -- Dr. Juan A. Balbuena Marine Zoology Unit Cavanilles Institute of Biodiversity and Evolutionary Biology University of Valencia [1]http://www.uv.es/~balbuena P.O. Box 22085 [2]http://www.uv.es/cavanilles/zoomarin/index.htm 46071 Valencia, Spain [3]http://cetus.uv.es/mullpardb/index.html e-mail: [4]j.a.balbu...@uv.estel. +34 963 543 658fax +34 963 543 733 NOTE! For shipments by EXPRESS COURIER use the following street address: C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain. References 1. http://www.uv.es/%7Ebalbuena 2. http://www.uv.es/cavanilles/zoomarin/index.htm 3. http://cetus.uv.es/mullpardb/index.html 4. mailto:j.a.balbu...@uv.es __ 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-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] transform dataframe with look-up table
On 7/25/2013 8:13 AM, Juan Antonio Balbuena wrote: Hello I hope that there is a simple solution to this apparently complex problem. Any help will be much appreciated: I have a dataframe with Left and Right readings (that is, elements in each row are paired). For instance, Left Right [1] 98 [2] 43 [3] 21 [4] 65 [5] 31 [6] 41 [7] 32 [8] 42 [9] 10 8 [10] 9 10 I need to produce a new data frame where the values are transformed according to a look-up table such as inputoutput [1] 5 1 [2]10 1 [3] 4 2 [4] 8 3 [5] 6 5 [6] 5 6 [7] 7 6 [8] 2 7 [9] 9 7 [10]107 [11] 2 8 So [1, ] in the new dataframe would be 7 3. Quite simple so far, but what makes things complicated is the multiple outputs for a single input. In this example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must yield two rows in its output counterpart: 1 3 and 7 3. Likewise the output for [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are missing as inputs the output for [5, ] should be NA NA. Thank you very much for your time. Juan Antonio Balbuena merge can handle both of these requirements. First, making the two datasets reproducible: Start - data.frame(Left=c(9,4,2,6,3,4,3,4,10,9), Right=c(8,3,1,5,1,1,2,2,8,10)) transformer - data.frame(input=c(5,10,4,8,6,5,7,2,9,10,2), output=c(1,1,2,3,5,6,6,7,7,7,8)) Then add a marker of the original row numbers so that the work can be checked more easily later (not really needed for the calculations): Start$rownum - seq_len(nrow(Start)) Two merge statements with the columns specified and all.x set to TRUE (to keep cases even without a match): End - merge(merge(Start, transformer, by.x=Left, by.y=input, all.x=TRUE), transformer, by.x=Right, by.y=input, all.x=TRUE) Then we can look at the output, resorted by the original row numbers: End[order(End$rownum),] which gives Right Left rownum output.x output.y 12 89 173 9 34 22 NA 1 12 37 NA 2 12 38 NA 10 56 456 11 56 451 3 13 5 NA NA 4 14 62 NA 5 23 7 NA7 6 23 7 NA8 7 24 827 8 24 828 13 8 10 913 14 8 10 973 15109 1071 16109 1077 -- Dr. Juan A. Balbuena Marine Zoology Unit Cavanilles Institute of Biodiversity and Evolutionary Biology University of Valencia [1]http://www.uv.es/~balbuena P.O. Box 22085 [2]http://www.uv.es/cavanilles/zoomarin/index.htm 46071 Valencia, Spain [3]http://cetus.uv.es/mullpardb/index.html e-mail: [4]j.a.balbu...@uv.estel. +34 963 543 658fax +34 963 543 733 NOTE! For shipments by EXPRESS COURIER use the following street address: C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain. References 1. http://www.uv.es/%7Ebalbuena 2. http://www.uv.es/cavanilles/zoomarin/index.htm 3. http://cetus.uv.es/mullpardb/index.html 4. mailto:j.a.balbu...@uv.es -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health Science University __ 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] transform dataframe with look-up table
Here's an approach that seems to work. I added an 11th case to your data since you did not have a case where both Left and Right had multiple values in the lookup table. This creates an id value so that we can merge left and right separately and then merge them back together: # Create test data frames Left - c(9, 4, 2, 6, 3, 4, 3, 4, 10, 9, 2) Right - c(8, 3, 1, 5, 1, 1, 2, 2, 8, 10, 5) ID - 1:11 Pair - data.frame(ID, Left, Right) input - c(5, 10, 4, 8, 6, 5, 7, 2, 9, 10, 2) output - c(1, 1, 2, 3, 5, 6, 6, 7, 7, 7, 8) Lookup - data.frame(input, output) # Merges Lout - merge(Pair, Lookup, by.x=Left, by.y=input, all.x=TRUE)[,c(ID, Left, output)] Rout - merge(Pair, Lookup, by.x=Right, by.y=input, all.x=TRUE)[, c(ID, Right, output)] names(Rout)[3] - outputR names(Lout)[3] - outputL merge(Lout, Rout, all=TRUE)[,c(1, 2, 4, 3, 5)] ID Left Right outputL outputR 1 19 8 7 3 2 24 3 2 NA 3 32 1 7 NA 4 32 1 8 NA 5 46 5 5 6 6 46 5 5 1 7 53 1 NA NA 8 64 1 2 NA 9 73 2 NA 7 10 73 2 NA 8 11 84 2 2 8 12 84 2 2 7 13 9 10 8 1 3 14 9 10 8 7 3 15 10910 7 1 16 10910 7 7 17 112 5 7 6 18 112 5 7 1 19 112 5 8 6 20 112 5 8 1 - David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Juan Antonio Balbuena Sent: Thursday, July 25, 2013 10:13 AM To: r-help@r-project.org Subject: [R] transform dataframe with look-up table Hello I hope that there is a simple solution to this apparently complex problem. Any help will be much appreciated: I have a dataframe with Left and Right readings (that is, elements in each row are paired). For instance, Left Right [1] 98 [2] 43 [3] 21 [4] 65 [5] 31 [6] 41 [7] 32 [8] 42 [9] 10 8 [10] 9 10 I need to produce a new data frame where the values are transformed according to a look-up table such as inputoutput [1] 5 1 [2]10 1 [3] 4 2 [4] 8 3 [5] 6 5 [6] 5 6 [7] 7 6 [8] 2 7 [9] 9 7 [10]107 [11] 2 8 So [1, ] in the new dataframe would be 7 3. Quite simple so far, but what makes things complicated is the multiple outputs for a single input. In this example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must yield two rows in its output counterpart: 1 3 and 7 3. Likewise the output for [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are missing as inputs the output for [5, ] should be NA NA. Thank you very much for your time. Juan Antonio Balbuena -- Dr. Juan A. Balbuena Marine Zoology Unit Cavanilles Institute of Biodiversity and Evolutionary Biology University of Valencia [1]http://www.uv.es/~balbuena P.O. Box 22085 [2]http://www.uv.es/cavanilles/zoomarin/index.htm 46071 Valencia, Spain [3]http://cetus.uv.es/mullpardb/index.html e-mail: [4]j.a.balbu...@uv.estel. +34 963 543 658 fax +34 963 543 733 NOTE! For shipments by EXPRESS COURIER use the following street address: C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain. References 1. http://www.uv.es/%7Ebalbuena 2. http://www.uv.es/cavanilles/zoomarin/index.htm 3. http://cetus.uv.es/mullpardb/index.html 4. mailto:j.a.balbu...@uv.es __ 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-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] MGCV: Degrees of freedom of smooth terms
On Tue, 2013-07-23 at 11:16 +0200, Christoph Scherber wrote: Dear all, This is just a quick question regarding degrees of freedom in GAM models fit by MGCV (using select=T): Can I roughly interpret them as: 1 df: linear effect of x on y 2 df: approximately quadratic of x on y 3 df: approximately cubic effect of x on y? Yes, approximately 1 df for a spatial term s(x,y): bilinear effect (?) or how would I call this? A bilinear effect would have two df, no? In a linear regression z ~ x + y would define a plane just like s(x, y) can and would use 2 df. 1 df for the entire s(x,y) implies an additional penalty such that less than 1df is spent in the `x` or `y` dimensions of the spline. And what does ref.df in the summary output mean; is this the unpenalized degrees of freedom for each term? IIRC, these are the dfs that are used in the tests reported. I am not familiar enough with the details to comment more. If you turn on Select = TRUE for example which adds an additional penalty then the ref.df can be much larger than the edf values. You might send an email to Simon Wood (or see if he picks up on this) for a (far) more authoritative answer on this part of your question. HTH G Thank you very much for answering! Best wishes, Christoph -- Gavin Simpson, PhD [t] +1 306 337 8863 Adjunct Professor, Department of Biology[f] +1 306 337 2410 Institute of Environmental Change Society [e] gavin.simp...@uregina.ca 523 Research and Innovation Centre [tw] @ucfagls University of Regina Regina, SK S4S 0A2, Canada __ 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] .eps files and powerpoint
On Vista with Powerpoint 2007, file2.eps crashes powerpoint, Once file.eps displayed, several times it crashed powerpoint. My task is now to see if ghostscript can read a pdf or ps or eps and convert it to png at res=300. Do you know the incantation for that? Rich On Thu, Jul 25, 2013 at 10:56 AM, Rmh r...@temple.edu wrote: i have parallels 8 as the vm. i can try a native pc this afternoon. Sent from my iPhone On Jul 25, 2013, at 10:42, Marc Schwartz marc_schwa...@me.com wrote: Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.edu wrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.com wrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content [[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.
Re: [R] .eps files and powerpoint
On Thu, Jul 25, 2013 at 9:30 AM, Richard M. Heiberger r...@temple.edu wrote: On Vista with Powerpoint 2007, file2.eps crashes powerpoint, Once file.eps displayed, several times it crashed powerpoint. My task is now to see if ghostscript can read a pdf or ps or eps and convert it to png at res=300. Do you know the incantation for that? pdftoppm can do it and is available for linux and windows, hopefully also on a Mac. It is a command line utility and on linux, you would run something like pdftoppm -png -r 300 file.pdf to convert file.pdf to file1.png, file2.png etc (one png file per page) at the resolution of 300 dpi. HTH, Peter pdftoppm has many options, see its man page (or google). __ 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] .eps files and powerpoint
Rich, That's scary. Well, I could make a comment about Vista, but that would take us in a whole new direction... ;-) As far as GS, for an EPS file to a PNG, try something along the lines of: gs -dSAFER -dBATCH -dNOPAUSE -r300 -dEPSCrop -sDEVICE=png16m -sOutputFile=file.png file.eps That seems to work for me on OSX. Regards, Marc On Jul 25, 2013, at 11:30 AM, Richard M. Heiberger r...@temple.edu wrote: On Vista with Powerpoint 2007, file2.eps crashes powerpoint, Once file.eps displayed, several times it crashed powerpoint. My task is now to see if ghostscript can read a pdf or ps or eps and convert it to png at res=300. Do you know the incantation for that? Rich On Thu, Jul 25, 2013 at 10:56 AM, Rmh r...@temple.edu wrote: i have parallels 8 as the vm. i can try a native pc this afternoon. Sent from my iPhone On Jul 25, 2013, at 10:42, Marc Schwartz marc_schwa...@me.com wrote: Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.edu wrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.com wrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content [[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. __ 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] Saving multiple rda-files as one rda-file
On Jul 22, 2013, at 4:18 AM, Dark wrote: Hi all, For a project we have to process some very large CSV files (up to 40 gig) To reduce them in size and increase operating performance I wanted to store them as RData files. Since it was to big I decided to split the csv and saving those parts as separate .RDA files. So far so good. Now I want to bind them all together to save as one RDA file again and this is supprisingly difficult. First I load my rda files into my environment: load(paste(rdaoutputdir, file1.rda, sep=)) load(paste(rdaoutputdir, file2.rda, sep=)) load(paste(rdaoutputdir, file3.rda, sep=)) etc Then I try to combine them into one object. Using rbind like this gives memory allocation problems ('Error: cannot allocate vector of size') objectToSave - rbind(object1, object2, object3) using pre-allocation gives me a factor level error. I used this code: nextrow - nrow(object1)+1 object1[nextrow:(nextrow+nrow(object2)-1),] - object2 # we need to assure unique row names row.names(object1) = 1:nrow(object1) rm(object2) gc() 15! warning messages: 1: In `[-.factor`(`*tmp*`, iseq, value = structure(c(1L, ... : invalid factor level, NA generated 2: In `[-.factor`(`*tmp*`, iseq, value = structure(c(1L, ... : invalid factor level, NA generated The warning messages suggests that the factor levels in object1, object2, object3 in corresponding columns are not the same. What can I do? You can identify which columns are factors and make the corresponding columns have levels that span the values. OR: Depending on the contents of that factor you could convert to character before the rbind operation. If the levels are not particularly long (in character length), that procedure might not expand the memory footprint very much. -- David Regards Derk David Winsemius Alameda, CA, USA __ 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] .eps files and powerpoint
perfect. since I really want to start with pdf or ps, these work on both Mac and Windows ## rmh for pdf gs -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=png16m -sOutputFile=testplot.png testplot.pdf ## rmh for ps gs -dSAFER -dBATCH -dNOPAUSE -r300 -dPSCrop -sDEVICE=png16m -sOutputFile=Living.png Living.ps ## Marc for eps gs -dSAFER -dBATCH -dNOPAUSE -r300 -dEPSCrop -sDEVICE=png16m -sOutputFile=file.png file.eps On Thu, Jul 25, 2013 at 12:44 PM, Marc Schwartz marc_schwa...@me.comwrote: Rich, That's scary. Well, I could make a comment about Vista, but that would take us in a whole new direction... ;-) As far as GS, for an EPS file to a PNG, try something along the lines of: gs -dSAFER -dBATCH -dNOPAUSE -r300 -dEPSCrop -sDEVICE=png16m -sOutputFile=file.png file.eps That seems to work for me on OSX. Regards, Marc On Jul 25, 2013, at 11:30 AM, Richard M. Heiberger r...@temple.edu wrote: On Vista with Powerpoint 2007, file2.eps crashes powerpoint, Once file.eps displayed, several times it crashed powerpoint. My task is now to see if ghostscript can read a pdf or ps or eps and convert it to png at res=300. Do you know the incantation for that? Rich On Thu, Jul 25, 2013 at 10:56 AM, Rmh r...@temple.edu wrote: i have parallels 8 as the vm. i can try a native pc this afternoon. Sent from my iPhone On Jul 25, 2013, at 10:42, Marc Schwartz marc_schwa...@me.com wrote: Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.edu wrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.com wrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content [[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.
[R] ggplot2: further query about back to back bar plots
Further to my recent post on this topic and thanks to help received already (thanks BTW), I've got back-to-back plots working nicely to give me population pyramids, with some overlaid point data from a different time period, using the code below. #packages library(ggplot2) library(reshape2) library(plyr) #sample data set.seed(33) df-data.frame(ag=c(1:18),males_year1=sample(100:200,18),females_year1=sample(100:200,18),males_year2=sample(100:200,18),females_year2=sample(100:200,18)) #melt the data set df-data.frame(melt(df,id=ag)) df #here is the plot p-ggplot(df)+ geom_bar(subset=.(df$variable==males_year1),stat=identity,aes(x=ag,y=value),fill=#FF)+ geom_bar(subset=.(df$variable==females_year1),stat=identity,aes(x=ag,y=-value),fill=#FF9333)+ geom_point(subset=.(df$variable==males_year2),stat=identity,aes(x=ag,y=value),size=3,colour=#330099)+ geom_point(subset=.(df$variable==females_year2),stat=identity,aes(x=ag,y=-value),size=3,colour=#CC3300)+ coord_flip()+ theme_bw()+ scale_y_continuous(limits=c(-200,200),breaks=seq(-200,200,50),labels=abs(seq(-200,200,50)))+ scale_x_continuous(limits=c(0,19),breaks=seq(1,18,1),labels=abs(seq(1,18,1)))+ xlab(age group)+ylab(population)+ theme_bw()+ xlab(age group)+ ylab(population)+ geom_text(y=-100,x=19.2,label=Females)+ geom_text(y=100,x=19.2,label=Males) p Two questions remaining. Firstly have I used a large amount of code to acheive this or is this about right for the effect that I'm after? Secondly I'm quite confused about how to put a legend onto a plot like this. I'm getting slowly into the ggplot way of doing things, but I'm totally baffled by legends; say I wanted a legend with an appropriate label for both genders and both time periods showing the colours of the bars and dots I've used here as examples, how do I do this? I've tried scale_fill with a bunch of arguments to no avial. I'm confused about where in the hierarchy of ggplot commands you actually build the legend and how you map it to your data. The usual trawl of the package pdf / cook book for R etc hasn't really helped. Can someone show me how to do this please? Many thanks. Gavin. __ 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] heatmap scale parameter
does change only the colors but dendrograms are unaffected. d - matrix(rnorm(100),nrow=20) heatmap(d) heatmap(d,scale=column) heatmap(d,scale=row) heatmap(d,scale=none) However scaling clearly affects clustering. see: d - scale(d) heatmap(d,scale=none) R version 3.0.1 (2013-05-16) -- Good Sport Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) ciao -- Witold Eryk Wolski __ 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] ggplot2: further query about back to back bar plots
Hello, I'm not an expert in ggplot2 graphics but I can (partly) answer to your first question. Inline. Em 25-07-2013 18:30, Gavin Rudge escreveu: Further to my recent post on this topic and thanks to help received already (thanks BTW), I've got back-to-back plots working nicely to give me population pyramids, with some overlaid point data from a different time period, using the code below. #packages library(ggplot2) library(reshape2) library(plyr) #sample data set.seed(33) df-data.frame(ag=c(1:18),males_year1=sample(100:200,18),females_year1=sample(100:200,18),males_year2=sample(100:200,18),females_year2=sample(100:200,18)) #melt the data set df-data.frame(melt(df,id=ag)) df #here is the plot p-ggplot(df)+ geom_bar(subset=.(df$variable==males_year1),stat=identity,aes(x=ag,y=value),fill=#FF)+ geom_bar(subset=.(df$variable==females_year1),stat=identity,aes(x=ag,y=-value),fill=#FF9333)+ geom_point(subset=.(df$variable==males_year2),stat=identity,aes(x=ag,y=value),size=3,colour=#330099)+ geom_point(subset=.(df$variable==females_year2),stat=identity,aes(x=ag,y=-value),size=3,colour=#CC3300)+ coord_flip()+ theme_bw()+ scale_y_continuous(limits=c(-200,200),breaks=seq(-200,200,50),labels=abs(seq(-200,200,50)))+ scale_x_continuous(limits=c(0,19),breaks=seq(1,18,1),labels=abs(seq(1,18,1)))+ xlab(age group)+ylab(population)+ theme_bw()+ xlab(age group)+ ylab(population)+ geom_text(y=-100,x=19.2,label=Females)+ geom_text(y=100,x=19.2,label=Males) p Two questions remaining. Firstly have I used a large amount of code to acheive this or is this about right for the effect that I'm after? You have repeated some code, the following lines show up twice. theme_bw()+ xlab(age group)+ ylab(population)+ Hope this helps, Rui Barradas Secondly I'm quite confused about how to put a legend onto a plot like this. I'm getting slowly into the ggplot way of doing things, but I'm totally baffled by legends; say I wanted a legend with an appropriate label for both genders and both time periods showing the colours of the bars and dots I've used here as examples, how do I do this? I've tried scale_fill with a bunch of arguments to no avial. I'm confused about where in the hierarchy of ggplot commands you actually build the legend and how you map it to your data. The usual trawl of the package pdf / cook book for R etc hasn't really helped. Can someone show me how to do this please? Many thanks. Gavin. __ 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-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] How to split two levels several times?
Hello, I think the following does what you want. (I don't know if it makes much sense but it works.) lens - rle(as.character(XXX$electrode))$lengths m - length(lens) %/% 2 idx - rep(1:m, sapply(1:m, function(.m) sum(lens[(2*.m - 1):(2*.m)]))) if(length(lens) %% 2 != 0){ idx - c(idx, rep(m + 1, lens[length(lens)])) sp_idx - split(idx, idx) n - length(sp_idx[[m]]) if(n %/% 2 length(sp_idx[[m + 1]])) sp_idx[[m]][(n %/% 2 + 1):n] - sp_idx[[m + 1]][1] else sp_idx[[m]][(n - length(sp_idx[[m + 1]]) + 1):n] - sp_idx[[m + 1]][1] idx - unlist(sp_idx) } sp - split(XXX, idx) sp Rui Barradas Em 25-07-2013 11:40, dennis1...@gmx.net escreveu: Hi Rui once more thank you for your help. But the code does so far not solve the problem because it still treats rows 17-22 (repeated appearance of electrode1) as one single level. However as can be seen by rows 1-3 (or rows 17-19 and rows 20-22) and the order of the length variable (row 1 = 5.7, row 2 = 6.3, row 3 = 6.2) electrode1 consists only of 3 rows. Maybe that was not made absolutely clear by me. As described in my mail before if by chance (or systematically) it happens to be that electrode1 appears right after each other in the table then the code should split it “half way”. So idx should not return [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 but instead 6 times number 4 at the end [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 Do you have any solution? Gesendet: Mittwoch, 24. Juli 2013 um 23:47 Uhr Von: Rui Barradas ruipbarra...@sapo.pt An: dennis1...@gmx.net Cc: r-help@r-project.org Betreff: Re: Aw: Re: Re: [R] How to split two levels several times? Hello, As for the first question, note that in the case you describe, the resulting list of df's will not be a split of the original, there will be a duplication in the final 4-1 and 1-3. The following is a hack but will do it. lens - rle(as.character(XXX$electrode))$lengths m - length(lens) %/% 2 idx - rep(1:m, sapply(1:m, function(.m) sum(lens[(2*.m - 1):(2*.m)]))) if(length(lens) %% 2 != 0) idx - c(idx, rep(m + 1, lens[length(lens)])) sp - split(XXX, idx) if(length(lens) %% 2 != 0){ idx2 - sp[[m]]$electrode == sp[[m]]$electrode[nrow(sp[[m]])] sp[[m + 1]] - rbind(sp[[m]][idx2, ], sp[[m + 1]]) } sp As for the second question, I'm not understanding it, can you post sample output? Rui Barradas Em 24-07-2013 13:58, dennis1...@gmx.net escreveu: Hi Rui the splitting code worked fine. Thanks for your help. Now I realized that the code cannot handle a table with levels that by chance (or systematically) repeatedly appear after each other. For instance this may happen if I need to extract the final two pairs of the table XXX below: electrode4+electrode1 and electrode1+electrode3. lens - rle(as.character(XXX$electrode))$lengths will return 3 2 3 2 6 6 3 and not 3 2 3 2 6 3 3 3 because it counts electrode1 double. split(XXX, idx) will produce 3 incorrect outputs instead of the required 4. This will also occur if I have systematic combinations 1-4 after each other for instance in a new table “XX” below where electrode4 appears twice. Is there a way to make splitting half-way between two of the same levels possible by predefining the length of each individual level? This would make the splitting code more robust. Thanks for advice. This is the table XXX electrode length electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode2 11.4 electrode2 9.7 electrode3 14.2 electrode3 14.8 electrode3 12.6 electrode2 11.4 electrode2 9.7 electrode4 17.0 electrode4 16.3 electrode4 17.8 electrode4 18.3 electrode4 16.9 electrode4 18.5 electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode1 5.7 electrode1 6.3 electrode1 6.2 electrode3 14.2 electrode3 14.8 electrode3 12.6 This is a simplified table XX electrode1 electrode2 electrode1 electrode3 electrode1 electrode4 electrode2 electrode1 electrode2 electrode3 electrode2 electrode4 electrode3 electrode1 electrode3 electrode2 electrode3 electrode4 electrode4 electrode1 electrode4 electrode2 electrode4 electrode3 Gesendet: Dienstag, 23. Juli 2013 um 13:36 Uhr Von: Rui Barradas ruipbarra...@sapo.pt An: dennis1...@gmx.net Cc: smartpink...@yahoo.com, 'r-help' r-help@r-project.org Betreff: Re: Aw: Re: [R] How to split two levels several times? Hello, It's better if you keep this on the list, the odds of getting more and better answers are greater. As for your new question, try the following. lens - rle(as.character(XXX$electrode))$lengths m - length(lens) %/% 2 idx - rep(1:m, sapply(1:m, function(.m) sum(lens[(2*.m - 1):(2*.m)]))) split(XXX, idx) Hope this helps, Rui Barradas Em 23-07-2013 11:41, dennis1...@gmx.net escreveu: Hi this type of splitting works for my specific example. Thanks for your help. I was not absolutely clear what I generally want. I'm looking for an option that generally permits splitting two
[R] Repeated measures Cox regression ??coxph??
Colleagues, Is there any R package that will allow one to perform a repeated measures Cox Proportional Hazards regression? I don't think coxph is set up to handle this type of problem, but I would be happy to know that I am not correct. I am doing a study of time to hip joint replacement. As each person has two hips, a given person can appear in the dataset twice, once for the left hip and once for the right hip, and I need to account for the correlation of data from a single individual. Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. __ 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] .eps files and powerpoint
On Jul 25, 2013, at 9:30 AM, Richard M. Heiberger wrote: On Vista with Powerpoint 2007, file2.eps crashes powerpoint, Once file.eps displayed, several times it crashed powerpoint. My task is now to see if ghostscript can read a pdf or ps or eps and convert it to png at res=300. Do you know the incantation for that? On a Mac that can be done with Preview.app. It used to be that you would use the Save as ... menu, but with the newer versions, it is File/Export... choose Format=PNG and resolution. -- David Rich On Thu, Jul 25, 2013 at 10:56 AM, Rmh r...@temple.edu wrote: i have parallels 8 as the vm. i can try a native pc this afternoon. Sent from my iPhone On Jul 25, 2013, at 10:42, Marc Schwartz marc_schwa...@me.com wrote: Rich, Any chance that you have access to a native Windows machine or to a colleague that does to try the files. I am wondering if there is any chance that there is something about running Office in Windows under a VM on OSX that might be involved in some manner. BTW, which VM (VMWare, Parallels, VirtualBox or ?) are you using? Marc On Jul 25, 2013, at 9:03 AM, Richard M. Heiberger r...@temple.edu wrote: The Header and Prolog of both file.eps and file2.eps are the same. On Thu, Jul 25, 2013 at 9:56 AM, Richard M. Heiberger r...@temple.edu wrote: file2.eps opens as a graph in windows PP 2010 and as an icon in PP 2013. RPlot2.pptx https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx opens as a graph in both windows PP and in Mac PP. On Wed, Jul 24, 2013 at 2:39 PM, Marc Schwartz marc_schwa...@me.com wrote: Rich, I don't have direct access to Windows and I don't run a VM on my Mac. I e-mailed two PPTX files created on my Mac (Office 2011) to a colleague who has Office 2010 on his Windows laptop. The first was the file on DropBox that I linked earlier, with the regular plot. The second is this PPTX file: https://www.dropbox.com/s/snm7cb9chrkcrff/RPlot2.pptx which contains this EPS file created with the barchart() code that you had below: https://www.dropbox.com/s/ujchnft7q3aa3pw/file2.eps I went over to his office and he could open both PPTX files on his laptop and both of the embedded EPS plots were viewable without issue. Can you open the PPTX file that I created above on your Windows instance? Marc On Jul 24, 2013, at 12:56 PM, Rmh r...@temple.edu wrote: office 2011 on mac, 2013 on windows. i see the same misbehavior in base and lattice. my standard simple test is plot(1:10) which is base. did you try the windows side yet? Rich snip of prior content [[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. David Winsemius Alameda, CA, USA __ 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] ggplot2: further query about back to back bar plots
On 7/25/2013 11:34 AM, Rui Barradas wrote: Hello, I'm not an expert in ggplot2 graphics but I can (partly) answer to your first question. Inline. Em 25-07-2013 18:30, Gavin Rudge escreveu: Further to my recent post on this topic and thanks to help received already (thanks BTW), I've got back-to-back plots working nicely to give me population pyramids, with some overlaid point data from a different time period, using the code below. #packages library(ggplot2) library(reshape2) library(plyr) #sample data set.seed(33) df-data.frame(ag=c(1:18),males_year1=sample(100:200,18),females_year1=sample(100:200,18),males_year2=sample(100:200,18),females_year2=sample(100:200,18)) #melt the data set df-data.frame(melt(df,id=ag)) df #here is the plot p-ggplot(df)+ geom_bar(subset=.(df$variable==males_year1),stat=identity,aes(x=ag,y=value),fill=#FF)+ geom_bar(subset=.(df$variable==females_year1),stat=identity,aes(x=ag,y=-value),fill=#FF9333)+ geom_point(subset=.(df$variable==males_year2),stat=identity,aes(x=ag,y=value),size=3,colour=#330099)+ geom_point(subset=.(df$variable==females_year2),stat=identity,aes(x=ag,y=-value),size=3,colour=#CC3300)+ coord_flip()+ theme_bw()+ scale_y_continuous(limits=c(-200,200),breaks=seq(-200,200,50),labels=abs(seq(-200,200,50)))+ scale_x_continuous(limits=c(0,19),breaks=seq(1,18,1),labels=abs(seq(1,18,1)))+ xlab(age group)+ylab(population)+ theme_bw()+ xlab(age group)+ ylab(population)+ geom_text(y=-100,x=19.2,label=Females)+ geom_text(y=100,x=19.2,label=Males) p Two questions remaining. Firstly have I used a large amount of code to acheive this or is this about right for the effect that I'm after? You have repeated some code, the following lines show up twice. theme_bw()+ xlab(age group)+ ylab(population)+ In addition to the repetition Rui notes, here is how I'd shorten it, albeit not by much (and with wrapping, actually more lines): p - ggplot(df)+ geom_bar(subset=.(variable==males_year1), stat=identity, position=identity, aes(x=ag,y=value), fill=#FF)+ geom_bar(subset=.(variable==females_year1), stat=identity, position=identity, aes(x=ag,y=-value), fill=#FF9333)+ geom_point(subset=.(variable==males_year2), aes(x=ag,y=value), size=3, colour=#330099)+ geom_point(subset=.(variable==females_year2), aes(x=ag,y=-value), size=3, colour=#CC3300)+ coord_flip()+ theme_bw()+ scale_y_continuous(population, limits=c(-200,200), breaks=seq(-200,200,50), labels=abs)+ scale_x_continuous(age group, limits=c(0,19.2), breaks=seq(1,18,1))+ annotate(geom=text, y=-100, x=19.2, label=Females)+ annotate(geom=text, y= 100, x=19.2, label=Males) Changes: * adding position=identity to the two geom_bar calls to suppress the Warning message: Stacking not well defined when ymin != 0 * dropping stat=identity in geom_point since that is the default * pulling the xlab and ylab into the scale_x_continuous and scale_y_continuous since you already have those calls * simplify the labels for the scales. For x, don't need to do anything to specify the labels; the work as expected based on the breaks. For y, rather than give a vector of labels, give a function which transforms the breaks into the labels you want (abs). * convert last two geom_text calls to annotations. * increased the limits in scale_x_continuous so that the annotations were not lost * the subset should not refer to df directly Hope this helps, Rui Barradas Secondly I'm quite confused about how to put a legend onto a plot like this. I'm getting slowly into the ggplot way of doing things, but I'm totally baffled by legends; say I wanted a legend with an appropriate label for both genders and both time periods showing the colours of the bars and dots I've used here as examples, how do I do this? I've tried scale_fill with a bunch of arguments to no avial. I'm confused about where in the hierarchy of ggplot commands you actually build the legend and how you map it to your data. The usual trawl of the package pdf / cook book for R etc hasn't really helped. Can someone show me how to do this please? Your confusion with legends likely comes from how ggplot approaches legends. A legend, for ggplot, shows the mapping between an aesthetic (color, shape, etc.) and the data values that it represents. Therefore, it is only necessary when there is a mapping between data and aesthetics. In your example, you manually set your colour/fill aesthetics, so there is no mapping, so there is no legend. The variables that are implied by your data are Sex and Year, so make those explicit: df2 - cbind(df, colsplit(df$variable, _, c(Sex, Year))) Now we can simplify the two geom_bar and two geom_point calls into one each, setting the sign of value based on the Sex column. I set the colour and fill to the interaction of Sex and Year (could have
Re: [R] Repeated measures Cox regression ??coxph??
On Jul 25, 2013, at 2:11 PM, John Sorkin jsor...@grecc.umaryland.edu wrote: Colleagues, Is there any R package that will allow one to perform a repeated measures Cox Proportional Hazards regression? I don't think coxph is set up to handle this type of problem, but I would be happy to know that I am not correct. I am doing a study of time to hip joint replacement. As each person has two hips, a given person can appear in the dataset twice, once for the left hip and once for the right hip, and I need to account for the correlation of data from a single individual. Thank you, John John, See Terry's 'coxme' package: http://cran.r-project.org/web/packages/coxme/index.html You also might find the following of interest: http://bjo.bmj.com/content/71/9/645.full.pdf http://www.ncbi.nlm.nih.gov/pubmed/6885 http://www.ncbi.nlm.nih.gov/pubmed/22078901 Regards, Marc Schwartz __ 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] Repeated measures Cox regression ??coxph??
On Jul 25, 2013, at 12:27 PM, Marc Schwartz wrote: On Jul 25, 2013, at 2:11 PM, John Sorkin jsor...@grecc.umaryland.edu wrote: Colleagues, Is there any R package that will allow one to perform a repeated measures Cox Proportional Hazards regression? I don't think coxph is set up to handle this type of problem, but I would be happy to know that I am not correct. I am doing a study of time to hip joint replacement. As each person has two hips, a given person can appear in the dataset twice, once for the left hip and once for the right hip, and I need to account for the correlation of data from a single individual. Thank you, John John, See Terry's 'coxme' package: http://cran.r-project.org/web/packages/coxme/index.html When I looked over the description of coxme, I was concerned it was not really designed with this in mind. Looking at Therneau and Grambsch, I thought section 8.4.2 in the 'Multiple Events per Subject' Chapter fit the analysis question well. There they compared the use of coxph( ...+cluster(ID),,...) withcoxph( ...+strata(ID),,...). Unfortunately I could not tell for sure which one was being described as superio but I think it was the cluster() alternative. I seem to remember there are discussions in the archives. -- David. You also might find the following of interest: http://bjo.bmj.com/content/71/9/645.full.pdf http://www.ncbi.nlm.nih.gov/pubmed/6885 http://www.ncbi.nlm.nih.gov/pubmed/22078901 Regards, Marc Schwartz __ 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. David Winsemius Alameda, CA, USA __ 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] constructing a daily time series
On Mon, Jul 22, 2013 at 11:17 PM, Pascal Oettli kri...@ymail.com wrote: Hello, ?zoo Regards, Pascal 2013/7/23 shanxiao shanx...@umail.iu.edu Dear all, I have a vector of observations through day, and based on it, I try to construct a daily time series with the R function ts(), but it seems that it only enables to construct a weekly, monthly, quarterly and yearly time series, does anyone know whether there is an option to build a daily time series? Thanks. Like Pascal said, you probably want to use the zoo/xts time series classes, but if you have reason to stick to ts() you can set the frequency to 365. I've written on this list before that frequency is a slightly subtle idea with time series (and you can find that post if you're interested), but it's not hard-coded to anything in particular. MW __ 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] Can't figure out why short figure won't work
I can't get the points and a and b to render correctly (they are squeezed into the axis) unless I make the height of the figure waste a lot of space. I'd appreciate any ideas. The code is below. Thanks! png('/tmp/z.png', width=480, height=100) par(mar=c(3,.5,1,.5)) plot.new() par(usr=c(-10, 410, -.04, 1.04)) par(mgp=c(1.5,.5,0)) axis(1, at=seq(0, 400, by=50)) axis(1, at=seq(0, 400, by=25), tcl=-.25, labels=FALSE) title(xlab='Mean Count') points(x, rep(-.02, length(x))) lines(rep(.25*1500, 2), c(-.04, .04), col='blue') lines(rep(.196*1500, 2), c(-.04, .04), col='blue') text(.25*1500, .07, 'a', col='blue') text(.196*1500,.07, 'b', col='blue') dev.off() It works if I use height=350. Frank version _ platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport -- Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University __ 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] Can't figure out why short figure won't work
I tried text(.25*1500, .14, 'a', col='blue') text(.196*1500,.14, 'b', col='blue') and got improved spacing. Another option is to take control of ylim, and extend the bottom of ylim a bit lower than the automatically defined value. Rich On Thu, Jul 25, 2013 at 6:54 PM, Frank Harrell f.harr...@vanderbilt.eduwrote: I can't get the points and a and b to render correctly (they are squeezed into the axis) unless I make the height of the figure waste a lot of space. I'd appreciate any ideas. The code is below. Thanks! png('/tmp/z.png', width=480, height=100) par(mar=c(3,.5,1,.5)) plot.new() par(usr=c(-10, 410, -.04, 1.04)) par(mgp=c(1.5,.5,0)) axis(1, at=seq(0, 400, by=50)) axis(1, at=seq(0, 400, by=25), tcl=-.25, labels=FALSE) title(xlab='Mean Count') points(x, rep(-.02, length(x))) lines(rep(.25*1500, 2), c(-.04, .04), col='blue') lines(rep(.196*1500, 2), c(-.04, .04), col='blue') text(.25*1500, .07, 'a', col='blue') text(.196*1500,.07, 'b', col='blue') dev.off() It works if I use height=350. Frank version _ platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport -- Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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.
[R] help with apply (lapply or sapply not sure)
I am reading in a bunch of files and then processing them all in the same way. I am sure there as a better way then to copy and past the code for each file. Here is what I've done so far InputFiles- as.character(list.files(~/ISLE/RWork/DataWarehouseMining/byCourse/)) #Path to the Course data files for (i in InputFiles) { # print(head(read.csv(paste(~/ISLE/RWork/DataWarehouseMining/byCourse/, i, sep= print(paste(Reading file ~/ISLE/RWork/DataWarehouseMining/byCourse/, i, sep=,)) assign(i, read.csv(paste(~/ISLE/RWork/DataWarehouseMining/byCourse/, i, sep=))) }#note last file is NOT a course file by the student information. Master-StudentInfoForRobertWUnitAt7A_2.csv #this is the last file CourseFiles -InputFiles[- c(15,16)] # ignore the student info ...7A.csv ...7A_2.csv #for each file I do the following #Bis 101 summary(BigInstBIS101.csv) B101 - BigInstBIS101.csv[-c(3,4,8)] summary(B101) B101$WH_ID - as.factor(B101$WH_ID) B101$SID - as.factor(B101$SID) B101$TERM - as.factor(B101$TERM) B101$CRN - as.factor(B101$CRN) B101$CRN_TRM - as.factor(B101$CRN_TRM) B101$INST_NUM - as.factor(B101$INST_NUM) B101$zGrade - with(B101, ave(GRADE., list(TERM, INST_NUM), FUN = scale)) write.csv(B101,B101.csv, row.names = FALSE) #Bis 2A B2A - BigInstBIS2A.csv[-c(3,4,8)] summary(B2A) B2A$WH_ID - as.factor(B2A$WH_ID) B2A$SID - as.factor(B2A$SID) B2A$TERM - as.factor(B2A$TERM) B2A$CRN - as.factor(B2A$CRN) B2A$CRN_TRM - as.factor(B2A$CRN_TRM) B2A$INST_NUM - as.factor(B2A$INST_NUM) B2A$zGrade - with(B2A, ave(GRADE., list(TERM, INST_NUM), FUN = scale)) write.csv(B2A,B2A.csv, row.names = FALSE) And so on for another 12 courses, however I am changing what I am doing as part of the reading in the file and don't want to replace the code in 14 different places. suggestions? Thanks! [[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.
Re: [R] Repeated measures Cox regression ??coxph??
On Jul 25, 2013, at 4:45 PM, David Winsemius dwinsem...@comcast.net wrote: On Jul 25, 2013, at 12:27 PM, Marc Schwartz wrote: On Jul 25, 2013, at 2:11 PM, John Sorkin jsor...@grecc.umaryland.edu wrote: Colleagues, Is there any R package that will allow one to perform a repeated measures Cox Proportional Hazards regression? I don't think coxph is set up to handle this type of problem, but I would be happy to know that I am not correct. I am doing a study of time to hip joint replacement. As each person has two hips, a given person can appear in the dataset twice, once for the left hip and once for the right hip, and I need to account for the correlation of data from a single individual. Thank you, John John, See Terry's 'coxme' package: http://cran.r-project.org/web/packages/coxme/index.html When I looked over the description of coxme, I was concerned it was not really designed with this in mind. Looking at Therneau and Grambsch, I thought section 8.4.2 in the 'Multiple Events per Subject' Chapter fit the analysis question well. There they compared the use of coxph( ...+cluster(ID),,...) withcoxph( ...+strata(ID),,...). Unfortunately I could not tell for sure which one was being described as superio but I think it was the cluster() alternative. I seem to remember there are discussions in the archives. David, I think that you raise a good point. The example in the book (I had to wait to get home to read it) is potentially different however, in that the subject's eye's were randomized to treatment or control, which would seem to suggest comparable baseline characteristics for each pair of eyes, as well as an active intervention on one side where a difference in treatment effect between each eye is being analyzed. It is not clear from John's description above if there is one hip that will be treated versus one as a control and whether the extent of disease at baseline is similar in each pair of hips. Presumably the timing of hip replacements will be staggered at some level, even if there is comparable disease, simply due to post-op recovery time and surgical risk. In cases where the disease between each hip is materially different, that would be another factor to consider, however I would defer to orthopaedic physicians/surgeons from a subject matter expertise consideration. It is possible that the bilateral hip replacement data might be more of a parallel to bilateral breast cancer data, if each breast were to be tracked separately. I have cc'd Terry here, hoping that he might jump in and offer some insights into the pros/cons of using coxme versus coxph with either a cluster or strata based approach, or perhaps even a frailty based approach as in 9.4.1 in the book. Regards, Marc -- David. You also might find the following of interest: http://bjo.bmj.com/content/71/9/645.full.pdf http://www.ncbi.nlm.nih.gov/pubmed/6885 http://www.ncbi.nlm.nih.gov/pubmed/22078901 Regards, Marc Schwartz __ 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. David Winsemius Alameda, CA, USA __ 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-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] Repeated measures Cox regression ??coxph??
David Thank you for your thoughts. The data I am analyzing do not come from a clinical trial but rather from a cohort study whose aim is to determine risk factors for surgical therapy to treat their joints. John Sent from my iPhone On Jul 25, 2013, at 9:15 PM, Marc Schwartz marc_schwa...@me.com marc_schwa...@me.com wrote: On Jul 25, 2013, at 4:45 PM, David Winsemius dwinsem...@comcast.net wrote: On Jul 25, 2013, at 12:27 PM, Marc Schwartz wrote: On Jul 25, 2013, at 2:11 PM, John Sorkin jsor...@grecc.umaryland.edu wrote: Colleagues, Is there any R package that will allow one to perform a repeated measures Cox Proportional Hazards regression? I don't think coxph is set up to handle this type of problem, but I would be happy to know that I am not correct. I am doing a study of time to hip joint replacement. As each person has two hips, a given person can appear in the dataset twice, once for the left hip and once for the right hip, and I need to account for the correlation of data from a single individual. Thank you, John John, See Terry's 'coxme' package: http://cran.r-project.org/web/packages/coxme/index.html When I looked over the description of coxme, I was concerned it was not really designed with this in mind. Looking at Therneau and Grambsch, I thought section 8.4.2 in the 'Multiple Events per Subject' Chapter fit the analysis question well. There they compared the use of coxph( ...+cluster(ID),,...) withcoxph( ...+strata(ID),,...). Unfortunately I could not tell for sure which one was being described as superio but I think it was the cluster() alternative. I seem to remember there are discussions in the archives. David, I think that you raise a good point. The example in the book (I had to wait to get home to read it) is potentially different however, in that the subject's eye's were randomized to treatment or control, which would seem to suggest comparable baseline characteristics for each pair of eyes, as well as an active intervention on one side where a difference in treatment effect between each eye is being analyzed. It is not clear from John's description above if there is one hip that will be treated versus one as a control and whether the extent of disease at baseline is similar in each pair of hips. Presumably the timing of hip replacements will be staggered at some level, even if there is comparable disease, simply due to post-op recovery time and surgical risk. In cases where the disease between each hip is materially different, that would be another factor to consider, however I would defer to orthopaedic physicians/surgeons from a subject matter expertise consideration. It is possible that the bilateral hip replacement data might be more of a parallel to bilateral breast cancer data, if each breast were to be tracked separately. I have cc'd Terry here, hoping that he might jump in and offer some insights into the pros/cons of using coxme versus coxph with either a cluster or strata based approach, or perhaps even a frailty based approach as in 9.4.1 in the book. Regards, Marc -- David. You also might find the following of interest: http://bjo.bmj.com/content/71/9/645.full.pdf http://www.ncbi.nlm.nih.gov/pubmed/6885 http://www.ncbi.nlm.nih.gov/pubmed/22078901 Regards, Marc Schwartz __ 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. David Winsemius Alameda, CA, USA __ 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. Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ 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] Can't figure out why short figure won't work
On 07/26/2013 08:54 AM, Frank Harrell wrote: I can't get the points and a and b to render correctly (they are squeezed into the axis) unless I make the height of the figure waste a lot of space. I'd appreciate any ideas. The code is below. Thanks! png('/tmp/z.png', width=480, height=100) par(mar=c(3,.5,1,.5)) plot.new() par(usr=c(-10, 410, -.04, 1.04)) par(mgp=c(1.5,.5,0)) axis(1, at=seq(0, 400, by=50)) axis(1, at=seq(0, 400, by=25), tcl=-.25, labels=FALSE) title(xlab='Mean Count') points(x, rep(-.02, length(x))) lines(rep(.25*1500, 2), c(-.04, .04), col='blue') lines(rep(.196*1500, 2), c(-.04, .04), col='blue') text(.25*1500, .07, 'a', col='blue') text(.196*1500,.07, 'b', col='blue') dev.off() It works if I use height=350. Frank I get an error (x is missing), but I would try: ... par(usr=c(-10,410,-0.1,1.04) ... Jim __ 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] simulating help
Dear all Could you please give me a link to a paper or article that explains how can I calculate type I error and power of a test using my data set by using R ? Also how can I do the same thing on a simulated data? I want this to compare between two tests I will be so grateful if you could help me with either one of them or both Thanks a lotAhmed [[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.
[R] number of items to replace is not a multiple of replacement length
Hi All, I have 5 stock values and i am calculating EWMA followed the logic as given ind following link.[ http://www.orecastingfinancialrisk.com/3.htmlhttp://www.forecastingfinancialrisk.com/3.html ] library('tseries') returns[,1]-returns[,1]-mean(returns[,1]) returns[,2]-returns[,2]-mean(returns[,2]) returns[,3]-returns[,3]-mean(returns[,3]) returns[,4]-returns[,4]-mean(returns[,4]) returns[,5]-returns[,5]-mean(returns[,5]) T-length(returns[,1]) T EWMA-matrix(nrow=T,ncol=5) lambda=0.94 S-cov(returns) S EWMA[1,] - S[lower.tri(S,diag=TRUE)] *Error in EWMA[1, ] - S[lower.tri(S, diag = TRUE)] : * * number of items to replace is not a multiple of replacement length* * * for(i in 2:T) { S- lambda*S +(1-lambda)*t(returns[i])%*% returns[i] EWMA[i,] - S[lower.tri(S,diag=TRUE)] } * * [[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.
[R] PPML in R
Hello, I would know the command for the poisson pseudo maximum likelihood in R for my gravity equations. Thank you. Cordially Laurent [[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.
Re: [R] Saving multiple rda-files as one rda-file
Hi, Yes maybe I should have been more clear on my problem. I want to append the different data-frames back into one variable ( rbind ) and save it as one R Data file. Regards Derk -- View this message in context: http://r.789695.n4.nabble.com/Saving-multiple-rda-files-as-one-rda-file-tp4672041p4672313.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.
[R] histogram with bars colored according to a vector of values
Dear all, Let's say I have the following data.frame: dat-data.frame(x=rnorm(100), y=rnorm(100,2)) and I plot a histogram of variable x, somethink like: hist(dat$x, breaks=-5:5) Now, I'd like to color each bar according to the mean of the cases according to y. For instance, the color of the bar between -2 and -1 should reflect the mean of variable y for the corresponding cases. Any suggestions? John [[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.
[R] Multiple interaction terms in GAMM-model
Dear all, I am trying to correlate a variable tau1 to a set of other variables (x1, x2, x3, x4), taking into account an interaction with time ('doy') and place ('region'), and taking into account dependency of data in time per object ID. My dataset looks like: doy objectIDregion tau1x1 x2 x3 x4 1 1 A 0.000.08 0.365764.1 0.001100 1 2 C 0.000.10 0.315074.3 0.000847 1 3 B 0.000.07 0.326460.9 0.000854 1 4 B 0.000.08 0.305863.2 0.000713 1 5 D 2.7169980.11 0.283593.7 0.000660 365 1 A 0.010.06 0.548927.3 0.003878 365 2 C 0.2340000.12 0.179823.1 0.000278 365 3 B 1.3535000.09 0.341737.8 0.000271 365 4 B 0.000.40 0.134713.4 0.000173 365 5 D 3.4780080.21 0.238437.7 0.000703 The total dataset consists of 151,840 rows (365 days x 416 object ID's) Since the data is dependent in time per objectID, I use a GAMM model with an autocorrelation function. Since each variable x1, x2, etc. is dependent on time and place, I should incorporate this as well. Therefore I am wondering if the following gamm-model is correct for my situation: model - gamm( tau1 ~ te( x1, by= doy ) + te( x1, by= factor( region ) ) + ... + te( x4, by= doy ) + te( x4, by= factor( region ) ) + factor( region ), correlation= corAR1(form= ~ doy|objectID ), na.action= na.omit ). Does anyone know if this is ok? Or should I use a model which also includes terms like te( x1 ) + ... + te( x4 ). And is the correlation function correct? Thanks so much!! Jeroen -- View this message in context: http://r.789695.n4.nabble.com/Multiple-interaction-terms-in-GAMM-model-tp4672297.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.
[R] lme (weights) and glht
Dear R members, I tried to fit an lme model and to use the glht function of multcomp. However, the glht function gives me some errors when using weights=varPower(). The glht error makes sense as glht needs factor levels and the model works fine without weights=. Does anyone know a solution so I do not have to change the lme model? Thanks Sibylle -- works fine ME$Diversity=factor(ME$Diversity) H08_lme-lme(log(Height2005_mean)~Diversity, data=ME, random=~1|Plot/ SubPlot, na.action=na.omit, subset=ME$Species==Pse_men, method=ML) summary(H08_lme) anova(H08_lme) g_H08_lme-glht(H08_lme, linfct=mcp(Diversity=Tukey)) print(summary(g_H08_lme)) -- using lme with weights I changed the order of factor() and introduced as.factor in the model H08_lme-lme(log(Height2008_mean)~as.factor(Diversity), data=ME, random=~1|Plot/SubPlot, weights=varPower(form=~Diversity), na.action=na.omit, subset=ME$Species==Ace_pse, method=ML) summary(H08_lme) anova(H08_lme) ME$Diversity=factor(ME$Diversity) g_H08_lme-glht(H08_lme, linfct=mcp(Diversity=Tukey)) Error in mcp2matrix(model, linfct = linfct) : Variable(s) Diversity have been specified in linfct but cannot be found in model! [[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.
[R] GGplot 2 – cannot get histogram and box plot axis to match.
Problem: I am trying to get the histogram and box plot x axis to match. I’ve tried using the expand_limits function to make the axis match but that didn’t make the axis match. The histogram’s axis are still consistently larger than the ones for the box plot (though the function did help). Does anyone have a suggestion as to what I should do instead? Background: I am building a Shiny app that displays a histogram below a bar chart for a set of data that a user uploads to the app. If you want to see the app, go here http://spark.rstudio.com/jclow/Archive20130725HistogramApp/ To run the app, select “Use Sample Data” , then select “MPG.city” under choose a column, then finally select box plot. Sample code: Below is a snippet of my code to demonstrate the problems I have. library(ggplot2) #sample data from ggplot2 data(Cars93, package = MASS) dataSet - Cars93 #variables to calculate the range to extend the axis dataVector - unlist(dataSet[,MPG.city]) dataRange - max(dataVector) - min(dataVector) graphRange - c(min(dataVector) - dataRange/5, max(dataVector) + dataRange/5) #making the box plot theBoxPlot - ggplot(dataSet,aes_string(x = MPG.city,y = MPG.city)) theBoxPlot = theBoxPlot + geom_boxplot() + expand_limits(y= graphRange) + coord_flip() print(theBoxPlot) #making the histogram thePlot - ggplot(dataSet,aes_string(x = MPG.city)) thePlot -thePlot + geom_histogram() + expand_limits(x= graphRange) print(thePlot) Thank you for taking the time to read this. John Clow UCSB Student __ 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.