[R] Brown’s One-parameter Linear Method in R
Dear R-Help members, Do you guys know any packages that implement Brown's exponential smoothing in R. I have using forecast package for most of my forecasting algorithms, but a new problem requires me to build a best fit forecast method & parameter selection for each forecast method with Brown's exponential smoothing as one of the forecast method. Would appreciate any help in this regard before I start looking to write a code from scratch. Thanks in advance for your help! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] DateTime wrong when exporting to csv in R
Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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] DateTime wrong when exporting to csv in R
Tried that..does not help :( On Wed, Aug 20, 2014 at 8:03 AM, Saurabh Agrawal sagra...@idrcglobal.com wrote: Maybe converting POSIXct to character string using format before writing to csv will help. On 20 August 2014 17:23, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] Sldf command returns negative value for date
It works :) Thanks so much! I tried searching a lot but I guess i missed this fact! On Thu, Aug 14, 2014 at 4:35 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Thu, Aug 14, 2014 at 3:47 PM, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! I am trying to increment date column of data frame so as to merge it with another data frame using sqldf: my query is : merge-sqldf(select m.* ,e.* from mdata as m left join event as e on date(m.Datest,'+1 day')=e.Start) The query returns null for all columns related to event table. When I investigated further with query : sqldf(select date(Datest,'+1 day')) from eventflight;) gives me -ve valued dates like : -4671-02-15 However this works: sqldf(select date(('2009-05-01'),'+1')) Dataframes are as follows: mdata : LOS Arrivals BookRange Datest 1 1283 0-42009-05-01 1 1650 0-42009-05-08 1 1302 5-92009-05-15 event: Event.Name Event.location Start End BirthdayTexas (US) 2009-05-022009-05-03 Anni Texas (US) 2009-05-09 2009-01-11 What am I doing wrong? This is a FAQ. See #4 here: http://sqldf.googlecode.com . The SQLite date function assumes its argument is a timestring but R Date class variables are transferred to SQLite as days since 1970-01-01 so just add 1. sqldf(select * from mdata as m left join event on Datest+1 = Start) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] Sldf command returns negative value for date
Hi All! I am trying to increment date column of data frame so as to merge it with another data frame using sqldf: my query is : merge-sqldf(select m.* ,e.* from mdata as m left join event as e on date(m.Datest,'+1 day')=e.Start) The query returns null for all columns related to event table. When I investigated further with query : sqldf(select date(Datest,'+1 day')) from eventflight;) gives me -ve valued dates like : -4671-02-15 However this works: sqldf(select date(('2009-05-01'),'+1')) Dataframes are as follows: mdata : LOS Arrivals BookRange Datest 1 1283 0-42009-05-01 1 1650 0-42009-05-08 1 1302 5-92009-05-15 event: Event.Name Event.location Start End BirthdayTexas (US) 2009-05-022009-05-03 Anni Texas (US) 2009-05-09 2009-01-11 What am I doing wrong? Thanks in advance SB [[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] Kmodes weighted version shows an error
Hi All! I have a data frame consisting of categorical variables on which I wish to perform kmode clustering with 20 clusters. I am trying to use Kmodes from R package klaR. The code works fine when I set use simple distance for clustering by setting weighted=FALSE in the function kmodes. However it throws an error when I try setting weighted=TRUE. Data frame : Df Zone Price Oc Peek Name Type Efficiency 1 W H Owned 0 TRIPLE Mech low 2 W H Owned 0 DOUBLE Mech low 3 W H Owned 0 TRIPLE Vidl high 4 E L Owned 0 DOUBLE Mechl low 5 S L Owned 0 BLACK Vid low 6 W H Owned 1 QUICK 7 Mech high The actual rows in Df is 5000 code : Kmodres-kmodes(Df, 20, weighted = TRUE ) Error :Error in n_obj[i] - weight[which(names == obj[different[i]])] : replacement has length zero Am i doing something wrong? Thank you in advance for any help. -SB [[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] Subsetting a dataframe by dynamic column name
Hi all! I am trying to drop columns from a data frame dynamically depending on user input. The dataframe whose columns need to be dropped is called Finaldata So here is what I do: V is a dataframe with columns v1 and v2 as follows v1 v2 1 1 Shape 2 0 Length 3 0 Rate v1 corresponds to user input, 1 if you want to drop the column, 0 otherwise v2 corresponds to column names of the all the columns in Finaldata I then use following code to drop columns for (i in 1:3) { if(V$v1[i]==1) { print(V$v2[i]) Finaldata-subset(Finaldata,select=-c(V$v2[i])) } } However v2 being type character is not accepted by subset. I read subset needs column names without quotes. I tried stripping off quotes through gsub and cat,however it din't help There are lot of columns and I cannot perform this individually on all columns. How do i go about it? Thanks! SB [[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] Subsetting a dataframe by dynamic column name
Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent all columns of Finaldata. I want to retain columns not provided as a choice for users plus the ones user chooses to keep. Thanks! On Thu, Mar 27, 2014 at 11:30 AM, Sarah Goslee sarah.gos...@gmail.comwrote: There are many ways. You're making it overly complicated Here, in an actual reproducible example (as you were requested to submit): V - data.frame(v1=c(1,0,0), v2=c(Shape, Length, Rate), stringsAsFactors=FALSE) Finaldata - data.frame(Shape = runif(5), Length = runif(5), Rate = runif(5)) # assuming names in V are not in the same order as columns in Finaldata # also assuming there might accidentally be names not in Finaldata Finaldata[, colnames(Finaldata) %in% V$v2[V$v1 == 0]] # more elegant? Finaldata[, colnames(Finaldata) %in% V$v2[!V$v1]] # not robust to errors in V Finaldata[, V$v2[!V$v1]] # assumes order of column names matches order of V Finaldata[, -V$v1] Sarah On Thu, Mar 27, 2014 at 11:09 AM, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi all! I am trying to drop columns from a data frame dynamically depending on user input. The dataframe whose columns need to be dropped is called Finaldata So here is what I do: V is a dataframe with columns v1 and v2 as follows v1 v2 1 1 Shape 2 0 Length 3 0 Rate v1 corresponds to user input, 1 if you want to drop the column, 0 otherwise v2 corresponds to column names of the all the columns in Finaldata I then use following code to drop columns for (i in 1:3) { if(V$v1[i]==1) { print(V$v2[i]) Finaldata-subset(Finaldata,select=-c(V$v2[i])) } } However v2 being type character is not accepted by subset. I read subset needs column names without quotes. I tried stripping off quotes through gsub and cat,however it din't help There are lot of columns and I cannot perform this individually on all columns. How do i go about it? Thanks! SB -- Sarah Goslee http://www.functionaldiversity.org -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] Subsetting a dataframe by dynamic column name
Thank you! Works like a charm! On Thu, Mar 27, 2014 at 12:19 PM, David Carlson dcarl...@tamu.edu wrote: That only requires two small changes in Sarah's first solution: Finaldata[, !colnames(Finaldata) %in% V$v2[V$v1 == 1]] Length Rate 1 0.53607323 0.01739951 2 0.15405615 0.11837908 3 0.04542388 0.53702702 4 0.15633703 0.68870041 5 0.35293973 0.38258981 - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sneha Bishnoi Sent: Thursday, March 27, 2014 11:06 AM To: Sarah Goslee Cc: r-help Subject: Re: [R] Subsetting a dataframe by dynamic column name Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent all columns of Finaldata. I want to retain columns not provided as a choice for users plus the ones user chooses to keep. Thanks! On Thu, Mar 27, 2014 at 11:30 AM, Sarah Goslee sarah.gos...@gmail.comwrote: There are many ways. You're making it overly complicated Here, in an actual reproducible example (as you were requested to submit): V - data.frame(v1=c(1,0,0), v2=c(Shape, Length, Rate), stringsAsFactors=FALSE) Finaldata - data.frame(Shape = runif(5), Length = runif(5), Rate = runif(5)) # assuming names in V are not in the same order as columns in Finaldata # also assuming there might accidentally be names not in Finaldata Finaldata[, colnames(Finaldata) %in% V$v2[V$v1 == 0]] # more elegant? Finaldata[, colnames(Finaldata) %in% V$v2[!V$v1]] # not robust to errors in V Finaldata[, V$v2[!V$v1]] # assumes order of column names matches order of V Finaldata[, -V$v1] Sarah On Thu, Mar 27, 2014 at 11:09 AM, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi all! I am trying to drop columns from a data frame dynamically depending on user input. The dataframe whose columns need to be dropped is called Finaldata So here is what I do: V is a dataframe with columns v1 and v2 as follows v1 v2 1 1 Shape 2 0 Length 3 0 Rate v1 corresponds to user input, 1 if you want to drop the column, 0 otherwise v2 corresponds to column names of the all the columns in Finaldata I then use following code to drop columns for (i in 1:3) { if(V$v1[i]==1) { print(V$v2[i]) Finaldata-subset(Finaldata,select=-c(V$v2[i])) } } However v2 being type character is not accepted by subset. I read subset needs column names without quotes. I tried stripping off quotes through gsub and cat,however it din't help There are lot of columns and I cannot perform this individually on all columns. How do i go about it? Thanks! SB -- Sarah Goslee http://www.functionaldiversity.org -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] Where Query in SQL
Hey all I am trying to use where in clause in sql query in R here is my code: sql.select-paste(select PERSON_NAME from UNITS where UNIT_ID in (',cathree,'),sep=) where cathree is 1 variable with 16 observations as follows UNIT_ID 1 205 2 209 3 213 4 217 5 228 6 232 7 236 8 240 9 245 10 249 11 253 12 257 13 268 14 272 15 276 16 280 but when i run this code, 0 rows are selected eventhough there exist 3 rows which satisfy the above query Thanks Sneha [[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] SQL queries in R
Hey all! I am trying to select a bunch of id's (data type -character) from a table and store them in a variable in R But when i do this, it automatically truncates the leading zero's in id's even though they are of character type. code is :- myconn-odbcConnect(testdata) sql.select-paste(select UNIT_ID from UNITS where (UNIT_TYPE=',unit,' and COMMUNITY=',property,'),sep=) unit_ids-sqlQuery(myconn,sql.select) print(unit_ids) is there anyway i can retain the UNIT_ID's as they are. Thanks! Sneha [[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] SQL queries in R
tried as.is ,gives an error, [1] 01000 10054 [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()). [2] [RODBC] ERROR: Could not SQLExecDirect 'select UNIT_ID from UNITS where (UNIT_TYPE='1X1' and COMMUNITY='SAN1193')' On Fri, Jun 7, 2013 at 3:21 PM, andrija djurovic djandr...@gmail.comwrote: ?sqlQuery as.is - argument Andrija On Jun 7, 2013 9:10 PM, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hey all! I am trying to select a bunch of id's (data type -character) from a table and store them in a variable in R But when i do this, it automatically truncates the leading zero's in id's even though they are of character type. code is :- myconn-odbcConnect(testdata) sql.select-paste(select UNIT_ID from UNITS where (UNIT_TYPE=',unit,' and COMMUNITY=',property,'),sep=) unit_ids-sqlQuery(myconn,sql.select) print(unit_ids) is there anyway i can retain the UNIT_ID's as they are. Thanks! Sneha [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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.