[R] For Loop Syntax
Hi there, Just wondering if someone can help me with the correct syntax to use with for loops? I have split my original file by count, wish to first of all assign new tables based on the splits. Then I just want to create a new variable. Please see code below. This code works outside of a loop so I am just trying to code so I don't have to repeat numerous times. Many thanks in advance, Bronagh A2 = split(A1,A1$count) for(i in 1:10){ trial[i] - data.frame(A2$`i`) trial[i]$BLD[i] - triali$BLD trial[i]$count - triali$BLD - NULL } [[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] Array
Hi there, Just wondering if anyone has any tips for using arrays? I am trying to convert the following SAS code to R: data A2; set A1; by subject_id; retain BX1-BX10i; array b(1:10) BX1-BX10 ; if first.subject_id then do ; do j=1 to 10; b(j) = .; end; i=1; end; b(i) = BX; i = i+1; if last.subject_id then output; run ; Many thanks in advance, Bronagh [[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] Array
Thanks for this, will have a look now. Much appreciated, -Original Message- From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk] Sent: 24 April 2009 11:40 To: Bronagh Grimes Cc: r-help@r-project.org Subject: Re: [R] Array Bronagh Grimes wrote: Just wondering if anyone has any tips for using arrays? You're presupposing that R works like SAS. It doesn't. This looks like a job for reshape (either Hadley Wickham's package or the built-in function). I am trying to convert the following SAS code to R: data A2; set A1; by subject_id; retain BX1-BX10i; array b(1:10) BX1-BX10 ; if first.subject_id then do ; do j=1 to 10; b(j) = .; end; i=1; end; b(i) = BX; i = i+1; if last.subject_id then output; run ; -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ 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] Count Code
Many thanks for this, I will try this code. Much appreciated. -Original Message- From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk] Sent: 22 April 2009 22:05 To: David Winsemius Cc: Bronagh Grimes; r-help@r-project.org Subject: Re: [R] Count Code David Winsemius wrote: On Apr 22, 2009, at 3:42 PM, Bronagh Grimes wrote: Hi there, I am interested in converting SAS code to R I wondered if anyone had any quick R code/tips for the following piece of test SAS code? Any feedback greatly appreciated. data A1; set A1; count + 1; by subject_id; if first.subject_id then count = 1; run; There were several solution offered a couple of months back to the challenge of replicating the features of the SAS _N_ construct. At least that is my memory of how it looks in SAS. You probably have the right books to consult for that question to construct a proper search: I think this one could be count - ave(a1$subject_id, a1$subject_id, FUN = seq_along) (assuming that count+1; increases the value from the previous record.) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ 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 Scripting on Linux Machine
Hi all, I am new to using R on a Linux machine I have a few questions on set-up. If anyone has experience in this area any advice would be greatly appreciated. - When I open R I have the option to do the following: o 'Run in Terminal' o 'Display' o 'Cancel' o 'Run' - My only option to open a window such as we find in the Windows version is to choose 'Run in Terminal'. - I really want to run a script where I can run sections of the code each time. - As we know in Windows we have the option to 'Open New Script' from here can choose 'Run line or Selection' - In this version I can indeed save a script open with 'Emacs', 'KWrite' OR 'Kate'. - But the only way I can run this script is to call the whole script using the source() function. - Does anyone know how I can implement a script that I can run as in the Windows version, whereby I can run one line at a time if I wish for testing purposes? Any help would be greatly appreciated. Many thanks in advance, [[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] Running Scripting on Linux Machine
Gavin, This is great, thank you. I will have a look at downloading this now. Much appreciated, Bronagh -Original Message- From: Gavin Simpson [mailto:gavin.simp...@ucl.ac.uk] Sent: 23 April 2009 09:47 To: Bronagh Grimes Cc: r-help@r-project.org Subject: Re: [R] Running Scripting on Linux Machine On Thu, 2009-04-23 at 09:31 +0100, Bronagh Grimes wrote: Hi all, I am new to using R on a Linux machine I have a few questions on set-up. If anyone has experience in this area any advice would be greatly appreciated. - When I open R I have the option to do the following: o 'Run in Terminal' o 'Display' o 'Cancel' o 'Run' - My only option to open a window such as we find in the Windows version is to choose 'Run in Terminal'. - I really want to run a script where I can run sections of the code each time. - As we know in Windows we have the option to 'Open New Script' from here can choose 'Run line or Selection' - In this version I can indeed save a script open with 'Emacs', 'KWrite' OR 'Kate'. - But the only way I can run this script is to call the whole script using the source() function. Not so in Emacs with ESS installed. You can run lines, regions, paragraphs etc. in an R instance within emacs itself. See the ess website for further details: http://ess.r-project.org I don't know about the other K* applications... G - Does anyone know how I can implement a script that I can run as in the Windows version, whereby I can run one line at a time if I wish for testing purposes? Any help would be greatly appreciated. Many thanks in advance, [[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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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 Edit() or Fix() on Linux Machine
Hi all, As I am new to using R on a Linux machine I have another question if that's ok. I am trying to use the fix() or edit() function on this Linux machine but I get the following error message: Error in dataentry(datalist, modes) : invalid device In addition: Warning message: In edit.data.frame(get(subx,envir=parent),title = subx, ...) : Unable to create fontset -*-fixed-medium-r-*-*-*-120-*-*-*-*-*-* It seems that I am trying to use an invalid device? Or I don't have the correct fonset? Has anyone else come across the same issue? And if so, how did you manage to resolve it? Any help would be greatly appreciated. Many thanks in advance, Bronagh [[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] Running Scripting on Linux Machine
Hi Gavin, I downloaded ESS can now see a buffer named '*ESS*' in my EMACS script file. To start an ESS process I followed the notes in the documentation: 1. To start an S session on Unix or on Windows when you use the Cygwin bash shell, simply type M-x S RET. 2. S will then (by default) ask the question 3. S starting data directory? 4. Enter the name of the directory you wish to start S from (that is, the directory you would have cd'd to before starting S from the shell). This directory should have a '.Data' subdirectory. 5. You will then be popped into a buffer with name '*S*' which will be used for interacting with the ESS process, and you can start entering commands. I can open R via step 1, but step 2 does not then happen. Any advice on how I go about opening the ESS for working on? Many thanks in advance, Bronagh -Original Message- From: Gavin Simpson [mailto:gavin.simp...@ucl.ac.uk] Sent: 23 April 2009 09:47 To: Bronagh Grimes Cc: r-help@r-project.org Subject: Re: [R] Running Scripting on Linux Machine On Thu, 2009-04-23 at 09:31 +0100, Bronagh Grimes wrote: Hi all, I am new to using R on a Linux machine I have a few questions on set-up. If anyone has experience in this area any advice would be greatly appreciated. - When I open R I have the option to do the following: o 'Run in Terminal' o 'Display' o 'Cancel' o 'Run' - My only option to open a window such as we find in the Windows version is to choose 'Run in Terminal'. - I really want to run a script where I can run sections of the code each time. - As we know in Windows we have the option to 'Open New Script' from here can choose 'Run line or Selection' - In this version I can indeed save a script open with 'Emacs', 'KWrite' OR 'Kate'. - But the only way I can run this script is to call the whole script using the source() function. Not so in Emacs with ESS installed. You can run lines, regions, paragraphs etc. in an R instance within emacs itself. See the ess website for further details: http://ess.r-project.org I don't know about the other K* applications... G - Does anyone know how I can implement a script that I can run as in the Windows version, whereby I can run one line at a time if I wish for testing purposes? Any help would be greatly appreciated. Many thanks in advance, [[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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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] Aggregate Function
Hi all, I am currently carrying out the following aggregate function: D2 - with(D1,aggregate(COST, list(FRUIT, VEG),FUN=sum)) The function is working fine but I am getting sum output in the following format: 1.750623e+09 How can I re-format the output to look like 1750622640.7? Many thanks in advance, Bronagh __ 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] Aggregate Function
Thanks a mil, will try that. -Original Message- From: Petr PIKAL [mailto:petr.pi...@precheza.cz] Sent: 23 April 2009 12:18 To: Bronagh Grimes Cc: r-help@r-project.org Subject: Odp: [R] Aggregate Function Try to set scipen in options. ?options e.g. options(scipen=12) Regards Petr r-help-boun...@r-project.org napsal dne 23.04.2009 12:30:11: Hi all, I am currently carrying out the following aggregate function: D2 - with(D1,aggregate(COST, list(FRUIT, VEG),FUN=sum)) The function is working fine but I am getting sum output in the following format: 1.750623e+09 How can I re-format the output to look like 1750622640.7? Many thanks in advance, Bronagh __ 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] Running Scripting on Linux Machine
Hi there, I am working in SLES / SLED 10. I use ALT+X then SHIFT+R? Many thanks, Bronagh -Original Message- From: Gavin Simpson [mailto:gavin.simp...@ucl.ac.uk] Sent: 23 April 2009 11:44 To: Bronagh Grimes Cc: r-help@r-project.org Subject: RE: [R] Running Scripting on Linux Machine On Thu, 2009-04-23 at 11:08 +0100, Bronagh Grimes wrote: Hi Gavin, I downloaded ESS can now see a buffer named '*ESS*' in my EMACS script file. To start an ESS process I followed the notes in the documentation: 1. To start an S session on Unix or on Windows when you use the Cygwin bash shell, simply type M-x S RET. 2. S will then (by default) ask the question 3. S starting data directory? 4. Enter the name of the directory you wish to start S from (that is, the directory you would have cd'd to before starting S from the shell). This directory should have a '.Data' subdirectory. 5. You will then be popped into a buffer with name '*S*' which will be used for interacting with the ESS process, and you can start entering commands. I can open R via step 1, but step 2 does not then happen. What OS? In my Emacs on Fedoras 7 through 10 the starting directory question appears in what is often called the status bar (along the bottom edge). It even proposes a starting directory for you. M-x R is what i use to start R. G Any advice on how I go about opening the ESS for working on? Many thanks in advance, Bronagh -Original Message- From: Gavin Simpson [mailto:gavin.simp...@ucl.ac.uk] Sent: 23 April 2009 09:47 To: Bronagh Grimes Cc: r-help@r-project.org Subject: Re: [R] Running Scripting on Linux Machine On Thu, 2009-04-23 at 09:31 +0100, Bronagh Grimes wrote: Hi all, I am new to using R on a Linux machine I have a few questions on set-up. If anyone has experience in this area any advice would be greatly appreciated. - When I open R I have the option to do the following: o 'Run in Terminal' o 'Display' o 'Cancel' o 'Run' - My only option to open a window such as we find in the Windows version is to choose 'Run in Terminal'. - I really want to run a script where I can run sections of the code each time. - As we know in Windows we have the option to 'Open New Script' from here can choose 'Run line or Selection' - In this version I can indeed save a script open with 'Emacs', 'KWrite' OR 'Kate'. - But the only way I can run this script is to call the whole script using the source() function. Not so in Emacs with ESS installed. You can run lines, regions, paragraphs etc. in an R instance within emacs itself. See the ess website for further details: http://ess.r-project.org I don't know about the other K* applications... G - Does anyone know how I can implement a script that I can run as in the Windows version, whereby I can run one line at a time if I wish for testing purposes? Any help would be greatly appreciated. Many thanks in advance, [[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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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] Count Code
Hi there, I am interested in converting SAS code to R I wondered if anyone had any quick R code/tips for the following piece of test SAS code? Any feedback greatly appreciated. data A1; set A1; count + 1; by subject_id; if first.subject_id then count = 1; run; [[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] Fix/Edit Error
Hi, I am wondering if anyone can help me with the following error. I am using R on a Linux machine and wish to use either the edit or fix function to look at the data. However, we I try to run either of these commands I get the following error Error in data entry(datalist, modes) : invalid device In addition: Warning message: In edit.data.frame(get(subx, envir = parent), title = subx, ...) : unable to create fontset -*-fixed-medium-r-*-*-*-120-*-*-*-*-*-* http://www.google.co.uk/search?hl=enei=h6ntSbXfHMeTjAe727ANsa=Xoi=sp ellresnum=0ct=resultcd=1q=Error+in+data+entry(datalist,+modes)+%3A+i nvalid+device+In+addition%3A+Warning+message%3A+In+edit.data.frame(get(s ubx,+envir+%3D+parent),+title+%3D+subx,+...)+%3A+unable+to+create+fontse t+-*-fixed-medium-r-*-*-*-120-*-*-*-*-*-*spell=1 Does anyone know how I can get around this so I can look at the data? Many thanks in advance, [[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.