[R] Adding points to a topo map
Hello R Users, I am trying to create a topographical map of Argentina with data points showing the location of 5 species. I first created a map using map() with points using latitude and longitude data for all 5 species as follows: library(maps) # Latitude / longitude coordinates of the 5 species: lat-c(-44.000, -43.000, -26.000, -33.000, -36.000) lon-c(-68.000, -70.000, -67.000, -61.000, -68.000) map(regions='AR', xlim=c(-75, -53), ylim=c(-56, -20), las=1) map.axes() points(lon, lat, pch=20, col=gray50, cex=1.8) This map does not give me the topographical relief I wanted, so I tried using the following code, which first downloads elevation information from NOAA and then creates a topo map of southern South American that includes Argentina: library(geomapdata) library(GEOmap) data - file(description = http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO5/TOPO/ETOPO5/ETOPO5.DAT;, open = rb, blocking = TRUE, encoding = getOption(encoding), raw = FALSE) data(ETOPO5) PLOC=list(LON=c(-80.000,-50.000),LAT=c(-56.000,-20.000), x=c(-80.000,-50.000), y=c(-56.000,-20.000) ) PROJ = setPROJ(type=2, LAT0=mean(PLOC$y) , LON0=mean(PLOC$x) ) COLS = settopocol() JMAT = GEOTOPO(ETOPO5, PLOC, PROJ, COLS$calcol, nx=1000, ny=1000, nb=8, mb=8, hb=12, PLOT=TRUE) I have attempted to add the 5 species points to this second map in a number of different ways, but I haven't been able to figure it out. In addition, I can not find documentation for how to do this in the GEOmap pdf or online. Can someone please help me add these lat / long points to the topo map? Thank you in advance for your time and help. K. Sheldon -- View this message in context: http://r.789695.n4.nabble.com/Adding-points-to-a-topo-map-tp4687330.html Sent from the R help mailing list archive at Nabble.com. [[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] Running Rmpi/OpenMPI issues
Hi, I have R 3.0.3 and OpenMPI 1.6.5. Here’s my test script: library(snow) nbNodes - 4 cl - makeCluster(nbNodes, MPI) clusterCall(cl, function() Sys.info()[c(nodename,machine)]) mpi.quit() And the mpirun command: /opt/openmpi-1.6.5-intel/bin/mpirun -np 1 -H host1,host2,host3,host4 R --no-save ~/test_mpi.R Here’s the output: cl - makeCluster(nbNodes, MPI) Loading required package: Rmpi 4 slaves are spawned successfully. 0 failed. clusterCall(cl, function() Sys.info()[c(nodename,machine)]) [[1]] nodename machine “host1 x86_64 [[2]] nodename machine “host1 x86_64 [[3]] nodename machine “host1 x86_64 [[4]] nodename machine “host1 x86_64 mpi.quit() I followed the instructions from: http://www.statistik.uni-dortmund.de/useR-2008/tutorials/useR2008introhighperfR.pdf , specifically to use -np 1 1. Why is it not running on the rest of the nodes? I can see all 4 processes on host1 and no orted daemon running. What should be the correct way to run this? 2. mpi.quit() just hangs there. Thanks! __ 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] Adding points to a topo map
Hi Why didn't you google for maps in R? Both the help pages for the GEOmap functions and the accompanying vignette for GEOmap clearly show how you should ad e.g. points to a map. Here is what you could have done after a careful reading of the documentation. library(geomapdata) data(japmap) plotGEOmap(japmap) points(139, 35.5, col = red, pch = *, cex = 5) Or this: PLOC=list(LON=c(137.008, 141.000), LAT=c(34.000, 36.992), x=c(137.008, 141.000), y=c(34.000, 36.992) ) PROJ = setPROJ(type=2, LAT0=mean(PLOC$y) , LON0=mean(PLOC$x) ) plotGEOmapXY(japmap, LIM=c(PLOC$LON[1], PLOC$LAT[1],PLOC$LON[2], PLOC$LAT[2]) , PROJ=PROJ, add = FALSE ) pointsGEOmapXY(lon = 139, lat = 35.5, PROJ = PROJ, col = red, pch = *, cex = 5) Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance Modeling Technology Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of kshel Sent: 22. marts 2014 00:18 To: r-help@r-project.org Subject: [R] Adding points to a topo map Hello R Users, I am trying to create a topographical map of Argentina with data points showing the location of 5 species. I first created a map using map() with points using latitude and longitude data for all 5 species as follows: library(maps) # Latitude / longitude coordinates of the 5 species: lat-c(-44.000, -43.000, -26.000, -33.000, -36.000) lon-c(-68.000, -70.000, -67.000, -61.000, -68.000) map(regions='AR', xlim=c(-75, -53), ylim=c(-56, -20), las=1) map.axes() points(lon, lat, pch=20, col=gray50, cex=1.8) This map does not give me the topographical relief I wanted, so I tried using the following code, which first downloads elevation information from NOAA and then creates a topo map of southern South American that includes Argentina: library(geomapdata) library(GEOmap) data - file(description = http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO5/TOPO/ETOPO5/ETO PO5.DAT, open = rb, blocking = TRUE, encoding = getOption(encoding), raw = FALSE) data(ETOPO5) PLOC=list(LON=c(-80.000,-50.000),LAT=c(-56.000,-20.000), x=c(-80.000,- 50.000), y=c(-56.000,-20.000) ) PROJ = setPROJ(type=2, LAT0=mean(PLOC$y) , LON0=mean(PLOC$x) ) COLS = settopocol() JMAT = GEOTOPO(ETOPO5, PLOC, PROJ, COLS$calcol, nx=1000, ny=1000, nb=8, mb=8, hb=12, PLOT=TRUE) I have attempted to add the 5 species points to this second map in a number of different ways, but I haven't been able to figure it out. In addition, I can not find documentation for how to do this in the GEOmap pdf or online. Can someone please help me add these lat / long points to the topo map? Thank you in advance for your time and help. K. Sheldon -- View this message in context: http://r.789695.n4.nabble.com/Adding-points- to-a-topo-map-tp4687330.html Sent from the R help mailing list archive at Nabble.com. [[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] How to import SAS file defining codes by SAS format catalog file
Also, once you are working in R, you need to familiarize yourself with the concept of a factor object. These are used to represent categories in R. Unlike SAS, R considers the categorical/quantitative distinction as part of the variable, e.g. in modeling you don't use CLASS directives, you ensure that the variable is a factor. You create factors from numerical codes with factor(), and in the process you may attach meaningful labels to the factor levels. (There's a whole book by Robert Muenchen designed to ease the transition from SAS to R.) -pd On 21 Mar 2014, at 10:06 , David Winsemius dwinsem...@comcast.net wrote: On Mar 21, 2014, at 12:57 AM, Kei_Takeuchi wrote: Dear Sir/Madam, Hello, this is Kei Takeuchi in Japan Automobile Research Institute. I am using R to import SAS file in NHTSA. This is happening since SAS is too expensive software. I successfully imoported SAS file which is *.sas7bdat by R. Now I want to define codes in SAS file like 1 to Alabama. Now all the data in SAS file is codes(for example 1,2,3...) which is hard to see. I use code book(published in UMTRI) to see what the codes mean) Defining code to text is possible in SAS where file called formats. sas7bcat. Is it possible by R? You might want to look at the functions in pkg: SAScii Author: Anthony Joseph Damico [aut, cre] URL: https://github.com/ajdamico/SAScii Thank you. Sincerely yours, Kei Takeuchi _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Kei Takeuchi Crash Safety Safety Research Division Japan Automobile Research Institute (JARI) Address: 2530 Karima, Tsukuba, Ibaraki 305-0822, Japan TEL: +81-29-856-0885 FAX: +81-29-856-1121 E-mail: kt...@jari.or.jp HP: http://www.jari.or.jp __ 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.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] How to split a Spell Data Frame into long format (irregular episode length)
Dear R-Users and developers, I am used to work with singular data but now I have to get my data of an spell-data-frame conducted in a big German longitudinal survey. The data structure is: persnr spelltypbegin end xf105 10 1 5 xf105 1 6 15 xf106 4 7 12 xf106 7 13 15 xf106 1 16 20 The variable spelltyp means a type of employment, 1 meaning full-time-employment, 4 meaning small part-time employment and so on. The begin and end are months, beginning with the first month of survey data collection as 1 (goes up to month 340). My goal is to transform it into a long-format file such as persnr spelltypmonth xf105 10 1 xf105 10 2 xf105 10 3 xf105 10 4 xf105 10 5 xf105 1 6 xf105 1 7 xf105 1 8 xf105 1 9 xf105 1 10 xf105 1 11 xf105 1 12 xf105 1 13 xf105 1 14 xf105 1 15 xf106 4 7 xf106 4 8 xf106 4 9 xf106 4 10 xf106 4 11 xf106 4 12 xf106 7 13 xf106 7 14 xf106 7 15 xf106 1 16 xf106 1 17 xf106 1 18 xf106 1 19 xf106 1 20 So what I want to do with R is to write a new row for every month and create a new variable where the number of the month is written in (one could keep the variables begin and end). Later on I want to reshape it into I wide-format to perform a sequence analysis. I am grateful for any advise - Thanks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-split-a-Spell-Data-Frame-into-long-format-irregular-episode-length-tp4687335.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] beta package for 3D PDF output
Dear All, my 3D PDF output package has been updated to fix incompatibility with recent versions of the rgl package. The source code of the package and demo output are at http://www2.iaas.msu.ru/tmp/u3d/rgl/ Sincerely, Michail __ 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] plotting vectors of different lengths
Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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] plotting vectors of different lengths
Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH, Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.comwrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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] plotting vectors of different lengths
Thankyou very much jorge. It would a great favor if i may know how to go from x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5 TO 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) 3 (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8) 4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8) 5 (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8) Thnakyou very in advance Eliza From: jorgeivanve...@gmail.com Date: Sat, 22 Mar 2014 22:26:01 +1100 Subject: Re: [R] plotting vectors of different lengths To: eliza_bo...@hotmail.com CC: r-help@r-project.org Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH,Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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] plotting vectors of different lengths
You are welcome, Eliza. If I understand correctly, the following will do: x - 1:8 y - 1:5 matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0((, r[1], ,, r[2], ))), ncol = length(x)) Best, Jorge.- On Sat, Mar 22, 2014 at 10:37 PM, eliza botto eliza_bo...@hotmail.comwrote: Thankyou very much jorge. It would a great favor if i may know how to go from x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5 TO 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) 3 (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8) 4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8) 5 (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8) Thnakyou very in advance Eliza From: jorgeivanve...@gmail.com Date: Sat, 22 Mar 2014 22:26:01 +1100 Subject: Re: [R] plotting vectors of different lengths To: eliza_bo...@hotmail.com CC: r-help@r-project.org Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH, Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.comwrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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] plotting vectors of different lengths
Thanks once again jorge. Regarding your previous reply, i got 50 warnings. Here is what I am trying to do xx-0.5*(-359.5:359.5) yy- 0.5*(-89.75:89.75) x - xx y - yy dat1-matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0((, r[1], ,, r[2], ))), ncol = length(x)) dat-noquote(dat1) library(maps) library(mapdata) map('worldHires') matpoints(t(dat), type = 'l') Thanks, Eliza From: jorgeivanve...@gmail.com Date: Sat, 22 Mar 2014 22:44:39 +1100 Subject: Re: [R] plotting vectors of different lengths To: eliza_bo...@hotmail.com CC: r-help@r-project.org You are welcome, Eliza. If I understand correctly, the following will do: x - 1:8y - 1:5 matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0((, r[1], ,, r[2], ))), ncol = length(x)) Best, Jorge.- On Sat, Mar 22, 2014 at 10:37 PM, eliza botto eliza_bo...@hotmail.com wrote: Thankyou very much jorge. It would a great favor if i may know how to go from x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5 TO 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) 3 (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8) 4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8) 5 (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8) Thnakyou very in advance Eliza From: jorgeivanve...@gmail.com Date: Sat, 22 Mar 2014 22:26:01 +1100 Subject: Re: [R] plotting vectors of different lengths To: eliza_bo...@hotmail.com CC: r-help@r-project.org Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH,Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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] plotting vectors of different lengths
Hi Eliza, You could also do: res - outer(y,x, FUN=function(u,v) paste0((,u,,,v,))) dimnames(res) - list(y,x) #or names(x) - x names(y) - y outer(y,x, FUN=function(u,v) paste0((,u,,,v,))) A.K. On Saturday, March 22, 2014 7:46 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: You are welcome, Eliza. If I understand correctly, the following will do: x - 1:8 y - 1:5 matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0((, r[1], ,, r[2], ))), ncol = length(x)) Best, Jorge.- On Sat, Mar 22, 2014 at 10:37 PM, eliza botto eliza_bo...@hotmail.comwrote: Thankyou very much jorge. It would a great favor if i may know how to go from x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5 TO 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) 3 (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8) 4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8) 5 (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8) Thnakyou very in advance Eliza From: jorgeivanve...@gmail.com Date: Sat, 22 Mar 2014 22:26:01 +1100 Subject: Re: [R] plotting vectors of different lengths To: eliza_bo...@hotmail.com CC: r-help@r-project.org Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH, Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.comwrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using points() command over an already existed image but got an error, Error in xy.coords(x, y) : 'x' and 'y' lengths differ.What i actually wanted to do was to plot the points in the following format. dat - read.table(text= 1 2 3 4 5 6 7 8 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8) ,sep=,header=TRUE,stringsAsFactors=FALSE) How can i do it? Thankyou very much indeed in advance. Eliza [[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-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] Fw: Removing blank cells and shifting data in df
Hi,May be this helps: dat1 - read.table(text=ID 1 2 3 4 5 6 A 1988 1995 2000 2000 2007 B 1995 1997 2000 2001 C 2001 2008 2010,sep=,header=TRUE,check.names=FALSE, fill=TRUE,stringsAsFactors=FALSE) dat1[is.na(dat1)] - dat1 # ID 1 2 3 4 5 6 #1 A 1988 1995 2000 2000 2007 #2 B 1995 1997 2000 2001 #3 C 2001 2008 2010 str(dat1) #'data.frame': 3 obs. of 7 variables: # $ ID: chr A B C # $ 1 : int 1988 1995 2001 # $ 2 : int 1995 1997 2008 # $ 3 : int 2000 2000 2010 # $ 4 : chr 2000 2001 # $ 5 : chr 2007 # $ 6 : chr #Suppose, you already read the data as shown in the post: dat - read.csv(Laura.csv,header=TRUE,stringsAsFactors=FALSE,check.names=FALSE) dat[is.na(dat)] - dat # ID 1 2 3 4 5 6 #1 A 1998 1995 2000 2000 2007 #2 B 1995 1997 2000 2001 #3 C 2001 2008 2010 dat[,-1] - do.call(rbind,lapply(seq_len(nrow(dat)),function(i) {x - dat[i,-1]; indx - x!=; c(x[indx],rep(,length(x)-length(x[indx])))})) dat # ID 1 2 3 4 5 6 #1 A 1998 1995 2000 2000 2007 #2 B 1995 1997 2000 2001 #3 C 2001 2008 2010 A.K. I would like to remove null values in a dataframe and shift all data left. I have something like: ID 1 2 3 4 5 6 A 1988 1995 2000 2000 2007 B 1995 1997 2000 2001 C 2001 2008 2010 I want something like: ID 1 2 3 4 5 6 A 1988 1995 2000 2000 2007 B 1995 1997 2000 2001 C 2001 2008 2010 Any suggestions on how to accomplish this? __ 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 a Spell Data Frame into long format (irregular episode length)
Hi, You could try: res - data.frame(dat[rep(1:nrow(dat),with(dat,end-begin+1)),1:2], month=unlist(apply(dat[,3:4],1,function(x) seq(x[1],x[2] row.names(res) - 1:nrow(res) A.K. On Saturday, March 22, 2014 6:29 AM, PabloNeruda s_ysi...@uni-bremen.de wrote: Dear R-Users and developers, I am used to work with singular data but now I have to get my data of an spell-data-frame conducted in a big German longitudinal survey. The data structure is: persnr spelltyp begin end xf105 10 1 5 xf105 1 6 15 xf106 4 7 12 xf106 7 13 15 xf106 1 16 20 The variable spelltyp means a type of employment, 1 meaning full-time-employment, 4 meaning small part-time employment and so on. The begin and end are months, beginning with the first month of survey data collection as 1 (goes up to month 340). My goal is to transform it into a long-format file such as persnr spelltyp month xf105 10 1 xf105 10 2 xf105 10 3 xf105 10 4 xf105 10 5 xf105 1 6 xf105 1 7 xf105 1 8 xf105 1 9 xf105 1 10 xf105 1 11 xf105 1 12 xf105 1 13 xf105 1 14 xf105 1 15 xf106 4 7 xf106 4 8 xf106 4 9 xf106 4 10 xf106 4 11 xf106 4 12 xf106 7 13 xf106 7 14 xf106 7 15 xf106 1 16 xf106 1 17 xf106 1 18 xf106 1 19 xf106 1 20 So what I want to do with R is to write a new row for every month and create a new variable where the number of the month is written in (one could keep the variables begin and end). Later on I want to reshape it into I wide-format to perform a sequence analysis. I am grateful for any advise - Thanks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-split-a-Spell-Data-Frame-into-long-format-irregular-episode-length-tp4687335.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.
[R] [R-pkgs] new version of effects package
Dear all, Sandy Weisberg, Michael Friendly, and I would like to announce a new version of the effects package, 3.0-0, now on CRAN; the new version should shortly percolate through the various CRAN mirrors. The major enhancement in this version of effects is the ability to plot partial residuals and smoothed partial residuals in effect displays for linear and generalized linear models, generalizing component-plus-residual plots. This new feature provides a visualization of the data against fitted terms in the model (or combinations of predictors) of arbitrary dimension and complexity. See the documentation for the partial.residuals argument in ?Effect and ?plot.eff. As always, suggestions and reports of problems are appreciated. Best, John John Fox, Professor McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] plotting vectors of different lengths
On Sat, Mar 22, 2014 at 7:10 AM, arun smartpink...@yahoo.com wrote: [ No no no. She (apparently) says she wants to plot a numeric grid given the x and y coordinates of the grid, not create a character matrix of strings representing the ordered pairs. set.seed(1234) x - runif(6) y - runif(5) dat - expand.grid(x=x,y=y) plot(y~x, data = dat) However, if what she really means (??) is that she wants to plot values in some way AT the coordinates, then she probably needs to look at ?contour or ?image (or their lattice or ggplot equivalents). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374(650) 467-7374(650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch Call Send SMS Add to Skype You'll need Skype CreditFree via Skype Call Send SMS Add to Skype You'll need Skype CreditFree via Skype __ 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] plotting vectors of different lengths
Dear Bert and Arun, Thankyou very much for your help. I am really obliged. :D Eliza Date: Sat, 22 Mar 2014 08:17:31 -0700 Subject: Re: [R] plotting vectors of different lengths From: gunter.ber...@gene.com To: smartpink...@yahoo.com; jorgeivanve...@gmail.com; eliza_bo...@hotmail.com CC: r-help@r-project.org On Sat, Mar 22, 2014 at 7:10 AM, arun smartpink...@yahoo.com wrote: [ No no no. She (apparently) says she wants to plot a numeric grid given the x and y coordinates of the grid, not create a character matrix of strings representing the ordered pairs. set.seed(1234) x - runif(6) y - runif(5) dat - expand.grid(x=x,y=y) plot(y~x, data = dat) However, if what she really means (??) is that she wants to plot values in some way AT the coordinates, then she probably needs to look at ?contour or ?image (or their lattice or ggplot equivalents). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374(650) 467-7374(650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch Call Send SMS Add to Skype You'll need Skype CreditFree via Skype Call Send SMS Add to Skype You'll need Skype CreditFree via Skype [[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] Determine breaks based on a break type...
Hi, you possibly know that there are a lot of methods to determine the number of bins. As a default R has the Sturges method. I think it does something like x - runif(100) mybreaks - hist(runif(x))$breaks r - max(x)-min(x) br - nclass.Sturges(x) #note this is a really simple approach and see edit(nclass.Sturges) brn - 0:br pretty(min(x)+brn*r/br, n=br) I tried to make the steps clear, the pretty function does the job in the end. Hope that helps (although I do not know if it is faster, but you can try it on your own), best daniel Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; meghatalmaz#243;: Jonathan Greenberg [j...@illinois.edu] Küldve: 2014. március 22. 17:15 To: r-help Tárgy: [R] Determine breaks based on a break type... R-helpers: I was wondering, given a vector of data, if there is a way to calculate the break points based on the breaks= parameter from histogram, but skipping all the other calculations (all I want is the breakpoints, not the frequencies). I can, of course, simply run the histogram and extract the break component: mybreaks - hist(runif(100))$breaks But is there a faster way to do this, if this is all I want? --j -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 __ 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.
[R] applying dglm() to a binary outcome
Dear R-Users, I have a question about the dglm() function from the dglm Package (V 1.6.2). The dglm() function fits double-generalized linear models as described in Smyth, G. K. (1989). Generalized linear models with varying dispersion. J. R. Statist. Soc. B, 51, 47-60. I use dglm() to estimate a simple logit (i.e. the dependent variable is a binary indicator) with varying dispersion. Code looks like this: example - data.frame( x1 = rnorm(1000,.5,1), x2 = rnorm(1000,0,1), y=rbinom(1000,1,.5)) model=dglm(y~x1,~x2,data=example,family=binomial(logit)) While the model converges, it keeps telling me the following warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! I interpret the warning as urging me that I should not apply dglm() to binary data. I am puzzled because 1) the standard glm() function works fine with binary data and 2) my reading of Smyth's paper suggests that the double-generalized linear model can be applied to binary data as well. So I guess my question is: should I ignore this warning or is there a statistical reason why the results might be biased in one way or the other? Thanks for any clarifying thoughts, Chris [[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] Extract Data form Website Tables
Hi Doran I'm also trying to scrape the leaderboard data. Did you happen to figure out how to extract the athlete's team/affiliate? Trying to do a bit of code to figure out which teams will qualify when individuals are removed. On Sunday, March 2, 2014 2:34:21 PM UTC-5, Doran, Harold wrote: This is fantastic, thank you. I¹ve modified the code to loop through all the pages and grab all rows of the HTML table. Thank you, Rui. On 3/2/14, 5:08 AM, Rui Barradas ruipba...@sapo.pt javascript: wrote: Hello, Maybe something like the following. #install.packages(XML, dep = TRUE) library(XML) url - http://games.crossfit.com/scores/leaderboard.php?stage=1sort=0division= 1region=0numberperpage=60page=0competition=0frontpage=0expanded=0fu ll=1year=14showtoggles=0hidedropdowns=0showathleteac=1athletename= data - readHTMLTable(readLines(url), which=1, header=TRUE) names(data) - gsub(\\n, , names(data)) names(data) - gsub( +, , names(data)) data[] - lapply(data, function(x) gsub(\\n, , x)) str(data) Hope this helps, Rui Barradas Em 01-03-2014 23:47, Doran, Harold escreveu: There is a website that populates a table with athlete scores during a competition. I would like to be able to extract those scores from the website and place them into a data frame if this is possible. The website is at the link below: http://games.crossfit.com/leaderboard One complication is that one must manually click through multiple pages as the table only populates a few hundred rows on one web page. In looking at the source code of the website, I think I can go to here and maybe grab scores, but I am not sure if R can someone read them in from this and populate a data frame and subsequently grab data from every page. http://games.crossfit.com/scores/leaderboard.php?loadfromcookies=1number perpage=60full=1showathleteac=1view-source: http://games.crossfit.com/s cores/leaderboard.php?loadfromcookies=1numberperpage=60full=1showathle teac=1 I have not done anything like this before, and so any guidance is appreciated. Thank you Harold [[alternative HTML version deleted]] __ r-h...@r-project.org javascript: 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-h...@r-project.org javascript: 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] Determine breaks based on a break type...
On 03/23/2014 03:15 AM, Jonathan Greenberg wrote: R-helpers: I was wondering, given a vector of data, if there is a way to calculate the break points based on the breaks= parameter from histogram, but skipping all the other calculations (all I want is the breakpoints, not the frequencies). I can, of course, simply run the histogram and extract the break component: mybreaks- hist(runif(100))$breaks But is there a faster way to do this, if this is all I want? Hi Jonathan, I assume that you want a function to define the number of classes rather than the alternative methods of simply specifying the number of breaks or the actual locations of breaks yourself. I know of three such functions: nclass.Sturges nclass.scott nclass.FD all in the grDevices package. You can call these functions directly and then calculate the break point locations by dividing the range of the observations into calculated number of classes: x-1:24 ncls-nclasses.Sturges(x) ncls [1] 6 # now decide whether you want right-closed intervals (the default) # and pad the left (default) or right side intwidth-(max(x) - (min(x)-1))/6 breaks-seq(min(x)-1,max(x),by=intwidth) It is debatable whether this is better than: hist(x,plot=FALSE)$breaks 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] [Re: Does a survival probability(the probability not, experiencing an event) have to be non-increasing?
The survival function, S(t), gives you the probability of surviving beyond time t starting from time 0. If you want to know the probability of surviving beyond time t *given* that you survived to get a heart surgery at time u0, that is a different function. It might be S(t)/S(u) depending on what you are willing to assume. From: Zhiyuan Sun [sam.d@gmail.com] Sent: Friday, March 21, 2014 10:48 PM To: Therneau, Terry M., Ph.D. Cc: r-help@r-project.org Subject: Re: [R] [Re: Does a survival probability(the probability not, experiencing an event) have to be non-increasing? Thanks Terry. Your explanation is right on the point. You solved my question about time-dependent covariate. When calculating survival at time t, you have to consider the exposure history before ant at time t. It is reasonable when we assume cumulative hazard before time t can be carried over to the next time, i.e., hazard is cumulative, no mater what happened. However,I still have a question. Is it possible that some time-dependent covairate(like heart surgery) that at some point, completely eliminated previous risk, so that cumulative hazard before that point can no longer be assumed to be carried over to next time point? For example, when a bad part of a machine was replaced, the machine got a new life. Or, when a surgery was done to a patient, the patient return to a healthy status. Intuitively, previous hazard should not be accumulated anymore after such major events happened to a person or a machine. They almost get new lives. It's like a renewal/recharge process. So, intuitively, survival should be recalculated then, instead of keep non-increasing. I hope I explained my question clearly. Thanks if you can provide any further clarification on my question. Thanks, Zhiyuan On Thu, Mar 20, 2014 at 8:46 AM, Therneau, Terry M., Ph.D. thern...@mayo.edu wrote: On 03/20/2014 06:00 AM, r-help-requ...@r-project.org wrote: My question is related to a cox model with time-dependent variable. When I think about it more, I get a little confused about non-increasing assumption for survival probability for an individual. For example, for a time-dependent ,say x, assuming increasing x increases the risk of event. Assume,time t1 t2. If at x at t1 x at t2, obviously, hazard at t1 will less than hazard at t2, assuming no other covariaates. But is it possible that s(t2|x at t2) s(t1|x at t1), since at t2, an individual is at greater risk. This is kind of confusing to me. Thanks for any helpful insights! Time dependent covariates and survival curves are confusing to a lot of people. The Cox model is a hazard model h(t, x) = h_0(t) exp(x beta) which means it is a model of the moment-by-moment risk. A time dependent model replaces x with x(t) which is the moment-by-moment value of x. After the model is fit, one can compute the time dependent cumulative hazard as H(t,x) = \integral_0^t h_0(s) exp(x(s) beta) ds and the survival is S = exp(-H). Since everthing inside the integral is positive H(t) has to be an increasing function of t, and thus S a decreasing one. The key thing to note is that H or S depend on the entire covariate history for a subject. If you have a subject whose value of x changes from 1 to 2 at time 10, when computing their survival at time 15 you cannot just use a value of 2 all the way from 0 to 15 in the formula. Many Cox model programs (e.g.SAS) allow for time dependent covariates when computing the Cox fit, but then only allow for fixed covariates when computing a curve. You can only do predictions for people whose covariates never change. (For some diseases I work with such people do not exist, e.g. in PBC your bilirubin WILL rise with time. So such a curve is useless). This adds to the confusion. Terry T. ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues __ 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] Latest question
Thankyou very much arun,I worked perfectly.:D Eliza Date: Sat, 22 Mar 2014 13:18:21 -0700 From: smartpink...@yahoo.com Subject: Re: Latest question To: r-help@r-project.org CC: eliza_bo...@hotmail.com HI Eliza, No problem. This should be faster: res2 - matrix(as.vector( mat1[row.names(mat1) %in% df1$Ry,colnames(mat1) %in% df1$Rx]),nrow=120, dimnames=list(NULL,colnames(res))) identical(res,res2) #[1] TRUE A.K. On Saturday, March 22, 2014 4:14 PM, eliza botto eliza_bo...@hotmail.com wrote: Thankyou very very much arun. Right now i cant have an acess to PC, as i am on the move. I will run the code when i get back to home in an hour and if there would be issue i'll definitely tell you. thanks once again Eliza Date: Sat, 22 Mar 2014 13:08:10 -0700 From: smartpink...@yahoo.com Subject: Re: Latest question To: r-help@r-project.org CC: eliza_bo...@hotmail.com Hi Eliza, May be this helps: set.seed(42) mat1 - matrix(sample(1:50,43200*720,replace=TRUE),ncol=720,dimnames=list(rep(y,each=120), x)) df1 - expand.grid(Ry=Ry,Rx=Rx) lst1 - lapply(seq_len(nrow(df1)),function(i) {x1- df1[i,]; mat1[row.names(mat1) %in% x1[1], colnames(mat1) %in% x1[2],drop=FALSE]}) res - do.call(cbind,lst1) dim(res) #[1] 120 408 colnames(res) - sapply(lst1,function(x) paste(colnames(x),unique(rownames(x)),sep=*)) row.names(res) - NULL res[1:3,1:3] #61.75*25.25 61.75*25.75 61.75*26.25 #[1,] 28 8 7 #[2,] 6 17 44 #[3,] 48 21 37 A.K. Dear Arun, I have a data frame of 43200 obs. of 720 variables (43200 rows and 120 columns), say df. Besides df, i also have two column vectors x (1 row and 720 columns) and y (360 rows and 1 column) which should be located in such a way that x covers the top of 720 rows of df, so in a way x is the column names of df. while y should be located in every 120th alternating rows of df so that it covers the entire rows of df (120*360=43200) which means y[1,]=-89.75 is the name of row 1 of df while y[2,] =-89.25 is the name of rows number 121st of df (you can assume that intermediate rows have the same names. So in way we can say that y[1,]=-89.75 is name of row1 to row120 of df and y[2,]=-89.25 is name of row 121 to 241 of df), similarly y[3,]=88.75 is the name of 241st row of df and so on untill 43200 rows of df are covered. we have two more vector, which will called refrence vectors R1 (1 row * 24 columns) and R2 (1 row * 17 columns), which are some of the selected values from x and y. let Rx- c(61.75, 62.25 ,62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25) Ry-c(25.25, 25.75 ,26.25, 26.75, 27.25, 27.75, 28.25, 28.75, 29.25, 29.75, 30.25, 30.75, 31.25, 31.75, 32.25, 32.75, 33.25) of the df i only want to select those columns which have column names similar to what is written in Rx and row names similar to Ry. so in the end we should have 408 column and 120 rows each containg a combination of Rx and Ry in the following manner, 61.75*25.2561.75*25.7561.75*26.25 61.75*26.75..62.25*25.2562.25*25.7562.25*26.25 62.25*26.75 120 values120 values120 values120 values120 values 120 values120 values120 values dput(x) c(-179.75, -179.25, -178.75, -178.25, -177.75, -177.25, -176.75, -176.25, -175.75, -175.25, -174.75, -174.25, -173.75, -173.25, -172.75, -172.25, -171.75, -171.25, -170.75, -170.25, -169.75, -169.25, -168.75, -168.25, -167.75, -167.25, -166.75, -166.25, -165.75, -165.25, -164.75, -164.25, -163.75, -163.25, -162.75, -162.25, -161.75, -161.25, -160.75, -160.25, -159.75, -159.25, -158.75, -158.25, -157.75, -157.25, -156.75, -156.25, -155.75, -155.25, -154.75, -154.25, -153.75, -153.25, -152.75, -152.25, -151.75, -151.25, -150.75, -150.25, -149.75, -149.25, -148.75, -148.25, -147.75, -147.25, -146.75, -146.25, -145.75, -145.25, -144.75, -144.25, -143.75, -143.25, -142.75, -142.25, -141.75, -141.25, -140.75, -140.25, -139.75, -139.25, -138.75, -138.25, -137.75, -137.25, -136.75, -136.25, -135.75, -135.25, -134.75, -134.25, -133.75, -133.25, -132.75, -132.25, -131.75, -131.25, -130.75, -130.25, -129.75, -129.25, -128.75, -128.25, -127.75, -127.25, -126.75, -126.25, -125.75, -125.25, -124.75, -124.25, -123.75, -123.25, -122.75, -122.25, -121.75, -121.25, -120.75, -120.25, -119.75, -119.25, -118.75, -118.25, -117.75, -117.25, -116.75, -116.25, -115.75, -115.25, -114.75, -114.25, -113.75, -113.25, -112.75, -112.25, -111.75, -111.25, -110.75, -110.25, -109.75, -109.25, -108.75, -108.25, -107.75,
Re: [R] Latest question
HI Eliza, No problem. This should be faster: res2 - matrix(as.vector( mat1[row.names(mat1) %in% df1$Ry,colnames(mat1) %in% df1$Rx]),nrow=120, dimnames=list(NULL,colnames(res))) identical(res,res2) #[1] TRUE A.K. On Saturday, March 22, 2014 4:14 PM, eliza botto eliza_bo...@hotmail.com wrote: Thankyou very very much arun. Right now i cant have an acess to PC, as i am on the move. I will run the code when i get back to home in an hour and if there would be issue i'll definitely tell you. thanks once again Eliza Date: Sat, 22 Mar 2014 13:08:10 -0700 From: smartpink...@yahoo.com Subject: Re: Latest question To: r-help@r-project.org CC: eliza_bo...@hotmail.com Hi Eliza, May be this helps: set.seed(42) mat1 - matrix(sample(1:50,43200*720,replace=TRUE),ncol=720,dimnames=list(rep(y,each=120), x)) df1 - expand.grid(Ry=Ry,Rx=Rx) lst1 - lapply(seq_len(nrow(df1)),function(i) {x1- df1[i,]; mat1[row.names(mat1) %in% x1[1], colnames(mat1) %in% x1[2],drop=FALSE]}) res - do.call(cbind,lst1) dim(res) #[1] 120 408 colnames(res) - sapply(lst1,function(x) paste(colnames(x),unique(rownames(x)),sep=*)) row.names(res) - NULL res[1:3,1:3] # 61.75*25.25 61.75*25.75 61.75*26.25 #[1,] 28 8 7 #[2,] 6 17 44 #[3,] 48 21 37 A.K. Dear Arun, I have a data frame of 43200 obs. of 720 variables (43200 rows and 120 columns), say df. Besides df, i also have two column vectors x (1 row and 720 columns) and y (360 rows and 1 column) which should be located in such a way that x covers the top of 720 rows of df, so in a way x is the column names of df. while y should be located in every 120th alternating rows of df so that it covers the entire rows of df (120*360=43200) which means y[1,]=-89.75 is the name of row 1 of df while y[2,] =-89.25 is the name of rows number 121st of df (you can assume that intermediate rows have the same names. So in way we can say that y[1,]=-89.75 is name of row1 to row120 of df and y[2,]=-89.25 is name of row 121 to 241 of df), similarly y[3,]=88.75 is the name of 241st row of df and so on untill 43200 rows of df are covered. we have two more vector, which will called refrence vectors R1 (1 row * 24 columns) and R2 (1 row * 17 columns), which are some of the selected values from x and y. let Rx- c(61.75, 62.25 ,62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25) Ry-c(25.25, 25.75 ,26.25, 26.75, 27.25, 27.75, 28.25, 28.75, 29.25, 29.75, 30.25, 30.75, 31.25, 31.75, 32.25, 32.75, 33.25) of the df i only want to select those columns which have column names similar to what is written in Rx and row names similar to Ry. so in the end we should have 408 column and 120 rows each containg a combination of Rx and Ry in the following manner, 61.75*25.25 61.75*25.75 61.75*26.25 61.75*26.75..62.25*25.25 62.25*25.75 62.25*26.25 62.25*26.75 120 values 120 values 120 values 120 values 120 values 120 values 120 values 120 values dput(x) c(-179.75, -179.25, -178.75, -178.25, -177.75, -177.25, -176.75, -176.25, -175.75, -175.25, -174.75, -174.25, -173.75, -173.25, -172.75, -172.25, -171.75, -171.25, -170.75, -170.25, -169.75, -169.25, -168.75, -168.25, -167.75, -167.25, -166.75, -166.25, -165.75, -165.25, -164.75, -164.25, -163.75, -163.25, -162.75, -162.25, -161.75, -161.25, -160.75, -160.25, -159.75, -159.25, -158.75, -158.25, -157.75, -157.25, -156.75, -156.25, -155.75, -155.25, -154.75, -154.25, -153.75, -153.25, -152.75, -152.25, -151.75, -151.25, -150.75, -150.25, -149.75, -149.25, -148.75, -148.25, -147.75, -147.25, -146.75, -146.25, -145.75, -145.25, -144.75, -144.25, -143.75, -143.25, -142.75, -142.25, -141.75, -141.25, -140.75, -140.25, -139.75, -139.25, -138.75, -138.25, -137.75, -137.25, -136.75, -136.25, -135.75, -135.25, -134.75, -134.25, -133.75, -133.25, -132.75, -132.25, -131.75, -131.25, -130.75, -130.25, -129.75, -129.25, -128.75, -128.25, -127.75, -127.25, -126.75, -126.25, -125.75, -125.25, -124.75, -124.25, -123.75, -123.25, -122.75, -122.25, -121.75, -121.25, -120.75, -120.25, -119.75, -119.25, -118.75, -118.25, -117.75, -117.25, -116.75, -116.25, -115.75, -115.25, -114.75, -114.25, -113.75, -113.25, -112.75, -112.25, -111.75, -111.25, -110.75, -110.25, -109.75, -109.25, -108.75, -108.25, -107.75, -107.25, -106.75, -106.25, -105.75, -105.25, -104.75, -104.25, -103.75, -103.25, -102.75, -102.25, -101.75, -101.25, -100.75, -100.25, -99.75, -99.25, -98.75, -98.25, -97.75, -97.25, -96.75, -96.25, -95.75, -95.25, -94.75, -94.25, -93.75, -93.25, -92.75, -92.25, -91.75, -91.25, -90.75, -90.25, -89.75, -89.25, -88.75,
[R] Merge two vectors into one
Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 Thanks for your help Tham -- View this message in context: http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge two vectors into one
Hi, May be this helps: a - 1:3 b - 4:6 z - as.vector(rbind(a,b)) z #[1] 1 4 2 5 3 6 #or z1 - setNames(c(a,b),rep(seq_along(a),2)) z1 - as.vector(z1[order(names(z1))]) z1 #[1] 1 4 2 5 3 6 A.K. Dear R users, Given two vectors x and y a=1 2 3 b=4 5 6 i want to combine them into a single vector z as 1 4 2 5 3 6 Thanks for your help Tham __ 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] time series processing - count of datestamp delta's, per group
Apologies if the question is a but naïve, I am a novice in time series data handling in R I have the following type of data, in a long format ( as called by the spacetime vignette the table contains also space, not noted here): User | Date | Otherdata | A | 01/01/2014 | aa A | 01/01/2014 | bb A | 01/01/2014 | cc B | 01/01/2014 | aa B | 05/01/2014 | cc A | 07/01/2014 | aa C | 05/02/2014 | xx C | 20/02/2014 | yy Etc [A,B,C, ] are user Ids (some strings). Date is converted into a Date format (2013-10-15) The table is sorted by User and then by Date, and is over 800K records long. There are about 20K users. User | Date | Otherdata | A | 2014-01-01 | aa A | 2014-01-01 | bb A | 2014-01-01 | cc A | 2014-01-07 | aa B | 2014-01-01 | aa B | 2014-01-05 | cc C | 2014-02-05 | xx C | 2014-02-20 | yy I want to: Get a frequency table ( and ultimately plot) of the count of differences (in days) between records of a user. Meaning, I would first get the unique days recorded: A | 2014-01-01 A | 2014-01-07 B | 2014-01-01 B | 2014-01-05 C | 2014-02-05 C | 2014-02-20 And then want to run the differences between timestamps within a group defined by the user, in days: A| 6 B| 4 C|15 Imagining that I have tens of thousands of records, I then want the table with the counts of differences ( across all users) ( in our case it would be 6, 4 and 15, all counte = 1) IN the larger sample, something like this: DeltaDays | Count 1 | 150 2 | 320 N | X I know there are all sorts of packages for time analysis, but I could not find a simple function like this (incl searching here http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf ). I assume that something working on a simple data frame would be sufficient, but I am happy ( prefer?) to use TS. I would appreciate any hints. The ultimate analysis involves also space, so hints in the direction of space-time are welcome. Ultimately, I would like to separate records for each user into a dataset that can be handled separately, but splitting it into a large number of files does not seem wise. Any hint also appreciated. Thanks, Martin [[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] points with-in boundaries of a map
Dear UseRs, I have a question regarding reading the coordinates within a country' map. I drew map of ireland by using the following commands library(maps) library(mapproj) map(world, ireland) map.axes() You can clearly see the axis labelled. What is want to do is to draw lines (both vertically and horizontally ) at an interval of 0.5. Which means if x-axis starts from -10 then the first be on -10 and second on -9.5 and so on. Similar has to be the case with y-axis. Afterwards I only want to read the coordinates of the point falling with in the boundary of ireland. I spent quite sometime while going through the previous posts but couldnt find the answer. Thankyou very much in advance, Elisa [[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] Conditional expressions in commands -- basic
Hi all, A simple question, new-ish to R, coming from Stata, and I yes I've looked at great length and not found ... In Stata I might write (with * in place of #) # regress y on x in the set of observations where a==1 reg y x if a==1 # descriptives on x where a==1 su x if a==1 # generate a logical depending on the value of a variable gen z = (a == 1) # or likewise for a numeric gen x = y if a == 1 # show the values of a variable based on the value of another variable di y if a ~= . # generate a logical based on missing-ness of a variable gen w = (a~=.) or any of many similar operations conditional on the value of a variable. Believe it or not this is a big obstacle to learning R. --- Richard Sherman __ 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] Conditional expressions in commands -- basic
Hi Richard, ?if ?ifelse ?subset ?[ depending on the specific operation. See inline. Given a data frame tdf with x, y, and a (or with vectors creating a data frame using): tdf - data.frame(x=x, y=y, a=a) On Sat, Mar 22, 2014 at 10:21 PM, Richard Sherman rss@gmail.com wrote: Hi all, A simple question, new-ish to R, coming from Stata, and I yes I've looked at great length and not found ... In Stata I might write (with * in place of #) # regress y on x in the set of observations where a==1 reg y x if a==1 lm(y ~ x, data=subset(tdf, a==1)) # descriptives on x where a==1 su x if a==1 summary(subset(tdf, a==1)$x) or summary(tdf[tdf$a == 1,]) or if they are vectors summary(x[a==1]) # generate a logical depending on the value of a variable gen z = (a == 1) z - a==1 # or likewise for a numeric gen x = y if a == 1 I'm not sure what this one is supposed to do. What's x if a isn't 1? But those examples should be enough to get you started, especially if you also read the Intro to R that comes with your R installation. Subsetting is a very basic operation, as you say, and pretty much every intro/tutorial I've read talks about it. I'm not sure where you looked in your extensive searching. Sarah # show the values of a variable based on the value of another variable di y if a ~= . # generate a logical based on missing-ness of a variable gen w = (a~=.) or any of many similar operations conditional on the value of a variable. Believe it or not this is a big obstacle to learning R. --- Richard Sherman -- Sarah Goslee http://www.functionaldiversity.org __ 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] points with-in boundaries of a map
On 03/23/2014 01:01 PM, eliza botto wrote: Dear UseRs, I have a question regarding reading the coordinates within a country' map. I drew map of ireland by using the following commands library(maps) library(mapproj) map(world, ireland) map.axes() You can clearly see the axis labelled. What is want to do is to draw lines (both vertically and horizontally ) at an interval of 0.5. Which means if x-axis starts from -10 then the first be on -10 and second on -9.5 and so on. Similar has to be the case with y-axis. Afterwards I only want to read the coordinates of the point falling with in the boundary of ireland. I spent quite sometime while going through the previous posts but couldnt find the answer. Thankyou very much in advance, Elisa Hi Elis(z)a, The grid function doesn't work properly on maps, probably due to the correction for the non-planar nature of the map. Try this: abline(v=seq(-10,-6.5,by=0.5)) abline(h=seq(51.5,55.5,by=0.5)) 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.