Re: [R] create variable

2016-10-12 Thread David Winsemius
> On Oct 12, 2016, at 11:20 AM, Ashta wrote: > > Hi David and all, > > I want run the following script in a loop but faced difficulty. > > trt=c(1,2,2,4,5,6,7,8) > for(i in 1:length (trt)) > { > try[i] <- (select trt, date1, date2, datediff(date1,date2) as > d12diff [i] from >

Re: [R] create variable

2016-10-12 Thread Ashta
Hi David and all, I want run the following script in a loop but faced difficulty. trt=c(1,2,2,4,5,6,7,8) for(i in 1:length (trt)) { try[i] <- (select trt, date1, date2, datediff(date1,date2) as d12diff [i] from dateTable where trt=[i]") } I would appreciate if you point me

Re: [R] create variable

2016-10-09 Thread Ashta
Thank you so much David! Your suggestions worked for me. On Sun, Oct 9, 2016 at 11:16 AM, David Winsemius wrote: > >> On Oct 9, 2016, at 7:56 AM, Ashta wrote: >> >> I am trying to query data from Hive service and create a variable. >> >> >> dbGetQuery(hivecon,"select date1, date2 from dateTab

Re: [R] create variable

2016-10-09 Thread Jeff Newmiller
This being the R-help mailing list, not being fluent in random SQL variants is normal. There is a place for discussing the intersection of R and databases where the intersection of R with such knowledge might be more typical. I suggest that Ashta read the Posting Guide to learn about appropriate

Re: [R] create variable

2016-10-09 Thread David Winsemius
> On Oct 9, 2016, at 7:56 AM, Ashta wrote: > > I am trying to query data from Hive service and create a variable. > > > dbGetQuery(hivecon,"select date1, date2 from dateTable limit 10") > date1, date2, Diif > 4/5/1999, 6/14/2000 > 7/2/1999, 6/26/2000 > 8/14/1999, 8/19/2000 > 11/10/1999, 9/1

Re: [R] create variable

2016-10-09 Thread David Winsemius
> On Oct 9, 2016, at 7:56 AM, Ashta wrote: > > I am trying to query data from Hive service and create a variable. > > > dbGetQuery(hivecon,"select date1, date2 from dateTable limit 10") > date1, date2, Diif > 4/5/1999, 6/14/2000 > 7/2/1999, 6/26/2000 > 8/14/1999, 8/19/2000 > 11/10/1999, 9/1

Re: [R] create variable

2016-10-09 Thread Bert Gunter
I think you need to do some homework on your own first. Have you gone through any R tutorials? -- there are many good ones on the web. Including ones on date-time processing in R. To answer your question directly, read up on date/time classes and functions with ?"date-time" . You may also find th

[R] create variable

2016-10-09 Thread Ashta
I am trying to query data from Hive service and create a variable. dbGetQuery(hivecon,"select date1, date2 from dateTable limit 10") date1, date2, Diif 4/5/1999, 6/14/2000 7/2/1999, 6/26/2000 8/14/1999, 8/19/2000 11/10/1999, 9/18/2000 8/25/2000, 6/5/2001 3/14/2012, 3/15/2004 Here is what I

Re: [R] Create variable with AND IF statement

2012-01-03 Thread Richard Kolodziej
Hello, thanks for the quick answers! Some answers were more useful to me than others but I really appreciate everybodys effort, reading and answering my question. I will try Dons approach because as he said, it looks quite readable. I'll need to take a closer look on the nested ifelse statements

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 4:22 PM, David Stevens wrote: Could it be NO. You are not reading the documentation for "if" carefully enough, despite several efforts to point you in the right direction. You cannot make literal transliterations of SPSS syntax work in the manner you imagine. -- Dav

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Stevens
Could it be if(variable1.fac == 0 & variable2.num == 0) {variable3 = 1} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 0 & variable2.num >= 0) {variable3 = 2} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 & variable2.nu

Re: [R] Create variable with AND IF statement

2012-01-02 Thread MacQueen, Don
I usually do this kind of thing like this: variable3 <- rep(1,length(variable1.fac)) variable3[ variable1.fac == 0 & variable2.num >= 1 ] <- 2 variable3[ variable1.fac == 1 & variable2.num == 0 ] <- 3 variable3[ variable1.fac == 1 & variable2.num >= 1 ] <- 4 This approach is easy to read and unde

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 10:42 AM, David Winsemius wrote: On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is qu

Re: [R] Create variable with AND IF statement

2012-01-02 Thread ONKELINX, Thierry
d Kolodziej Verzonden: maandag 2 januari 2012 10:11 Aan: r-help@r-project.org Onderwerp: [R] Create variable with AND IF statement Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck wi

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (var

[R] Create variable with AND IF statement

2012-01-02 Thread Richard Kolodziej
Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variabl

Re: [R] create variable names using paste

2011-11-20 Thread Uwe Ligges
On 20.11.2011 15:32, Alaios wrote: Dear all, I would like based on a variable values, like threshold<- 90 to create variables name that will load data sets For example paste('mystring',threshold,sep="")<-load('myfile') This is a FAQ! You probably want to assign into a list. But if you rea

[R] create variable names using paste

2011-11-20 Thread Alaios
Dear all, I would like based on a variable values, like threshold<- 90 to create variables name that will load data sets For example paste('mystring',threshold,sep="")<-load('myfile') How I can doi something like that in R? B.R Alex [[alternative HTML version deleted]] _

Re: [R] Create Variable names dynamically

2011-04-02 Thread David Winsemius
On Mar 31, 2011, at 3:46 PM, Henrique Dallazuanna wrote: Take a look in ?assign On Thu, Mar 31, 2011 at 5:42 PM, Noah Silverman > wrote: Hi, I want to create variable names from within my code, but can't find any documentation for this. An example is probably the best way to illustrate.

Re: [R] Create Variable names dynamically

2011-03-31 Thread jim holtman
The best thing to do is to understand how to use 'list' for this purpose. Much easier to handle the information. On Thu, Mar 31, 2011 at 4:42 PM, Noah Silverman wrote: > Hi, > > I want to create variable names from within my code, but can't find any > documentation for this. > > An example is p

Re: [R] Create Variable names dynamically

2011-03-31 Thread Noah Silverman
Perfect. Thank You On Mar 31, 2011, at 1:47 PM, Mark Leeds wrote: > hi noah: assign(thing you paste, 123, envir=whatever) should work I think. > > > On Thu, Mar 31, 2011 at 4:42 PM, Noah Silverman > wrote: > Hi, > > I want to create variable names from within my code, but can't find any

Re: [R] Create Variable names dynamically

2011-03-31 Thread Henrique Dallazuanna
Take a look in ?assign On Thu, Mar 31, 2011 at 5:42 PM, Noah Silverman wrote: > Hi, > > I want to create variable names from within my code, but can't find any > documentation for this. > > An example is probably the best way to illustrate. I am reading data in from > a file, doing a bunch of s

[R] Create Variable names dynamically

2011-03-31 Thread Noah Silverman
Hi, I want to create variable names from within my code, but can't find any documentation for this. An example is probably the best way to illustrate. I am reading data in from a file, doing a bunch of stuff, and want to generate variables with my output. (I could make a "list of lists" and n

Re: [R] Create variable by name

2010-10-06 Thread Ralf B
e- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of Ralf B >> Sent: Wednesday, October 06, 2010 10:32 AM >> To: r-help Mailing List >> Subject: [R] Create variable by name >> >> Can one create a variable thro

Re: [R] Create variable by name

2010-10-06 Thread Greg Snow
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Ralf B > Sent: Wednesday, October 06, 2010 10:32 AM > To: r-help Mailing List > Subject: [R] Create variable by name > > Can one create a variable th

Re: [R] Create variable by name

2010-10-06 Thread David Winsemius
On Oct 6, 2010, at 12:58 PM, David Winsemius wrote: On Oct 6, 2010, at 12:32 PM, Ralf B wrote: Can one create a variable through a function by name Isn't that what "<-" does? createVariable <- function(name) { outputVariable = name name <- NULL } after calling createVa

Re: [R] Create variable by name

2010-10-06 Thread David Winsemius
On Oct 6, 2010, at 12:32 PM, Ralf B wrote: Can one create a variable through a function by name Isn't that what "<-" does? createVariable <- function(name) { outputVariable = name name <- NULL } after calling createVariable("myVar") ?assign # and isn't this covered in

Re: [R] Create variable by name

2010-10-06 Thread Jeffrey Spies
An alternative to Peter's solution: createVariable <- function(name) {assign(name, NULL, envir=.GlobalEnv)} Jeff. On Wed, Oct 6, 2010 at 12:32 PM, Ralf B wrote: > Can one create a variable through a function by name > > createVariable <- function(name) { >        outputVariable = name >        

Re: [R] Create variable by name

2010-10-06 Thread Peter Langfelder
On Wed, Oct 6, 2010 at 9:32 AM, Ralf B wrote: > Can one create a variable through a function by name > > createVariable <- function(name) { >        outputVariable = name >        name <- NULL > } > > after calling > > createVariable("myVar") > > I would like to have a variable myVar initialized w

Re: [R] Create variable by name

2010-10-06 Thread Peter Langfelder
On Wed, Oct 6, 2010 at 9:32 AM, Ralf B wrote: > Can one create a variable through a function by name > > createVariable <- function(name) { >        outputVariable = name >        name <- NULL > } > > after calling > > createVariable("myVar") > > I would like to have a variable myVar initialized w

[R] Create variable by name

2010-10-06 Thread Ralf B
Can one create a variable through a function by name createVariable <- function(name) { outputVariable = name name <- NULL } after calling createVariable("myVar") I would like to have a variable myVar initialized with NULL in my environment. Is this possible? Ralf