Re: [R] data reshape

2019-12-19 Thread Bert Gunter
Did you even make an attempt to do this? -- or would you like us do all
your work for you?

If you made an attempt, show us your code and errors.
If not, we usually expect you to try on your own first.
If you have no idea where to start, perhaps you need to spend some more
time with tutorials to learn basic R functionality before proceeding.

Bert

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Dec 19, 2019 at 6:01 PM Yuan Chun Ding  wrote:

> Hi R users,
>
> I have a folder (called genotype) with 652 files; the file names are
> GTEX-1A3MV.out, GTEX-1A3MX.out, GTEX-1B8SF.out, etc; in each file,  only
> one column of data without a header as below
> 201
> 2/2
> 238
> 3/4
> 245
> 1/2
> .
> 983255
> 3/3
> 983766
> None
>
>
> A total of 20528 rows;
>
> I need to read all those 652 files in the genotype folder and then reshape
> the one column in each file as:
> SampleID 201238245   983255
>  983766
> GTEX-1A3MV 2/2 3/41/2 3/3
>None
>
> There are 10264 data columns plus the sample ID column, so 10265 columns
> in total after data reshaping.
>
> After reading those 652 file and reshape the one column in each file, I
> will stack them by the rbind function, then I have a file with a dimension
> of 653 row, 10265 column.
>
>
> Thank you,
>
> Ding
>
> --
> 
> -SECURITY/CONFIDENTIALITY WARNING-
>
> This message and any attachments are intended solely for the individual or
> entity to which they are addressed. This communication may contain
> information that is privileged, confidential, or exempt from disclosure
> under applicable law (e.g., personal health information, research data,
> financial information). Because this e-mail has been sent without
> encryption, individuals other than the intended recipient may be able to
> view the information, forward it to others or tamper with the information
> without the knowledge or consent of the sender. If you are not the intended
> recipient, or the employee or person responsible for delivering the message
> to the intended recipient, any dissemination, distribution or copying of
> the communication is strictly prohibited. If you received the communication
> in error, please notify the sender immediately by replying to this message
> and deleting the message and any accompanying files from your system. If,
> due to the security risks, you do not wish to rec
>  eive further communications via e-mail, please reply to this message and
> inform the sender that you do not wish to receive further e-mail from the
> sender. (LCP301)
> 
>
> [[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.
>

[[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] data reshape

2019-12-19 Thread Yuan Chun Ding
Hi R users,

I have a folder (called genotype) with 652 files; the file names are  
GTEX-1A3MV.out, GTEX-1A3MX.out, GTEX-1B8SF.out, etc; in each file,  only one 
column of data without a header as below
201
2/2
238
3/4
245
1/2
.
983255
3/3
983766
None


A total of 20528 rows;

I need to read all those 652 files in the genotype folder and then reshape the 
one column in each file as:
SampleID 201238245   983255 
983766
GTEX-1A3MV 2/2 3/41/2 3/3 
None

There are 10264 data columns plus the sample ID column, so 10265 columns in 
total after data reshaping.

After reading those 652 file and reshape the one column in each file, I will 
stack them by the rbind function, then I have a file with a dimension of 653 
row, 10265 column.


Thank you,

Ding

--

-SECURITY/CONFIDENTIALITY WARNING-  

This message and any attachments are intended solely for the individual or 
entity to which they are addressed. This communication may contain information 
that is privileged, confidential, or exempt from disclosure under applicable 
law (e.g., personal health information, research data, financial information). 
Because this e-mail has been sent without encryption, individuals other than 
the intended recipient may be able to view the information, forward it to 
others or tamper with the information without the knowledge or consent of the 
sender. If you are not the intended recipient, or the employee or person 
responsible for delivering the message to the intended recipient, any 
dissemination, distribution or copying of the communication is strictly 
prohibited. If you received the communication in error, please notify the 
sender immediately by replying to this message and deleting the message and any 
accompanying files from your system. If, due to the security risks, you do not 
wish to rec
 eive further communications via e-mail, please reply to this message and 
inform the sender that you do not wish to receive further e-mail from the 
sender. (LCP301)


[[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.


Re: [R] [FORGED] Re: date

2019-12-19 Thread Rolf Turner

On 20/12/19 1:30 am, Bert Gunter wrote:

"But the important point is:
If you know the structure of the data you want to
parse, then it is best to tell R (or any other language)
this structure explicitly. "

Fortune nomination!


Second the nomination!

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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.


Re: [R] date

2019-12-19 Thread David Stevens
Val

Another all-base R solution:

as.Date(strptime(gs$date,format="%m/%d/%y"))

or if you want to add a time field later

as.POSIXct(strptime(gs$date,format="%m/%d/%y")))

since strptime produces a list version of the date: class is POSIXt and the 
subclass is POSIXlt, that can be convenient for extracting elements like month, 
day of the year, minute, etc. The actual date/time information is returned as 
the number of seconds since 1970-01-01 00:00:00 UTC but the representation is 
as in your gs.d1 below.

It can be a bit tricky when daylight savings time comes into play but that's 
for another post.

David


On 12/17/2019 3:51 PM, Val wrote:

Hi All,

I wanted to to convert character date  mm/dd/yy  to -mm-dd
The sample data and my attempt is shown below

gs <-read.table(text="ID date
A1   09/27/03
A2   05/27/16
A3   01/25/13
A4   09/27/19",header=TRUE,stringsAsFactors=F)

Desired output
  ID date  d1
 A1 09/27/03 2003-09-27
 A2 05/27/16 2016-05-27
 A3 01/25/13 2012-04-25
 A4 09/27/19 2019-09-27

I used this
gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")

but I got NA's.

How do I get my desired result?
Thank you.

__
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.


--
David K Stevens, PhD, PE
Environmental Engineering Division
Civil and Environmental Engineering
Utah State University
8200 Old Main Hill
Logan, UT 83200-8200
(435) 797-3229
david.stev...@usu.edu

[[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] Nominations sought for the 2021 ASA Statistical Computing and Graphics Award

2019-12-19 Thread Yan, Jun
(Apologies for cross-posting)

Dear Colleagues,

The ASA Section on Statistical Computing and Section on Statistical Graphics 
are inviting nominations of deserving individuals or teams for the 2021 ASA 
Statistical Computing and Graphics Award 
(https://community.amstat.org/jointscsg-section/awards/computing-graphics-award).
 

The Statistical Computing and Graphics Award recognizes an individual or team 
for innovation in computing, software, or graphics that has had a significant 
impact on statistical practice or research. The past awardees are Luke Tierney 
(2019), Bill Cleveland (2016), and Robert Gentleman and Ross Ihaka (2010). The 
prize carries with it a cash award of $5,000 plus an allowance of up to $1,000 
for travel to the Joint Statistical Meetings (JSM) where the award will be 
presented. Nominations packets have to be submitted by email to Dr. Jun Yan, 
the Awards Chair of the two sections, at jun@uconn.edu by May 31, 2020. Dr. 
Jun Yan is the Award Chair of the two sections and will be pleased to answer 
any questions about the submission process and the preparation of the 
nomination materials.

Qualifications

The prize-winning contribution will have had significant and lasting impacts on 
statistical computing, software or graphics.

The nominee should be a member of the ASA. The Statistical Computing and 
Graphics Award Committee will review the nominations and make the final 
determination of who, if any, should receive the award. The award may not be 
given to a sitting member of the Awards Committee or a sitting member of the 
Executive Committee of the Section of Statistical Computing or the Section of 
Statistical Graphics.

Nomination and Award Dates

Nominations are due by May 31, 2020 for an award to be presented at the 2021 
JSM.

Nominations should be submitted as a complete packet, consisting of:

+ a nomination letter, no longer than four pages, addressing points in the 
selection criteria
+ nominee’s curriculum vita(e)
+ a minimum of 3 (and no more than 4) supporting letters, each no longer than 
two pages

Selection Process

The Committee will consist of the Chairs and Past Chairs of the Section of 
Statistical Computing and the Section of Statistical Graphics. The committee 
will meet at the 2020 JSM to select the recipient(s) of the award.

Jun Yan, Awards Chair
ASA Section on Statistical Computing and
Section on Statistical Graphics
__
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-es] UTILIZAR ETLUtils PARA CARGAR DATOS DE UNA BASE DE DATOS SQL SERVER

2019-12-19 Thread PVM
Estoy tratando de cargar datos de una base de datos SQL SERVER.
Inicialmente utilizaba la siguiente implementación con los paquetes "dbi" y
"odbc":
connection <- dbConnect(odbc(),
dsn = "SQL_Server",
driver = "SQLServer",
Server = "", database = "",
uid = askForPassword("Database user"),
pwd = askForPassword("Database password"),
port = 1433)

Una vez establecida la conexión ejecutaba una consulta SQL.
Todo esto funciona perfectamente.
Sin embargo, para una cantidad elevada de líneas tengo problemas con la
memoria, y he visto que una alternativa es utilizar el paquete ETLUtils
para que guarde el objeto en disco en lugar de guardarlo en la memoria.
El problema es que no soy capaz de realizar una implementación válida.
Ejecuto:
datos_cliente <- read.dbi.ffdf(query = query, dbConnect.args = list(drv =
"SQLServer", dbname = "",

username = "", password = ""),
   first.rows = 100, next.rows = 1000,
VERBOSE=TRUE)
Y obtengo el error:

Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘dbConnect’ for
signature ‘"character"’


Porque no consigue conectarse a la base de datos. Creo que tengo algo mal
en esta implementación pero no sé cómo debería ser.
¿Alguna idea?
Muchas gracias.
Un saludo,
Puri Velasco

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] date

2019-12-19 Thread Jeff Newmiller
I agree that having convenience functions can be in the spirit of R, but I find 
that lubridate puts the cart before the horse so I avoid it. Specifically, the 
conceptual sequence

- convert character to timestamp in GMT
- "fix" erroneous timestamps to correct time zone

more inefficient and error-prone than

- convert character to timestamp specifying correct timezone

or

- specify default timezone
- convert character to timestamp using default timezone

but apparently others disagree so we have a whole sub-culture working with GMT 
by default.

On December 19, 2019 4:45:41 AM PST, Eric Berger  wrote:
>[ ... taking the bait regarding the "unnecessary discussion" ... ]
>
>The "Fortune nomination" that Bert sent includes the phrase
>
>"...then it is best to tell R ..."
>
>What metric is being used to do the ranking to get the "best"? If the
>metric is related to "providing the most unambiguous information to R"
>then I agree that providing the structure explicitly is best.
>However, often what is "best" is to minimize programmer time. With
>lubridate, I know that providing the clue 'ymd' is enough to have it
>perform the date conversion correctly. That is minimal effort on my
>part,
>which gives it a top ranking from my point of view.
>
>Also, to broaden this "unnecessary discussion" I would argue that the
>lubridate package may even be more "in the spirit of R" than what is
>being
>proposed with the explicit structural information. Clearly R is far
>from
>being a strongly typed language. If you really want to provide explicit
>structural information maybe you would be better off with a language
>such
>as C++. :-)
>
>
>
>
>
>On Thu, Dec 19, 2019 at 2:30 PM Bert Gunter 
>wrote:
>
>>
>>
>> "But the important point is:
>> If you know the structure of the data you want to
>> parse, then it is best to tell R (or any other language)
>> this structure explicitly. "
>>
>> Fortune nomination!
>>
>> -- Bert
>>
>>
>>
>>
>>
>>
>> Thu, Dec 19, 2019, 2:49 AM Enrico Schumann 
>wrote:
>>
>>>
>>> Quoting Eric Berger :
>>>
>>> > Martin  writes: "there's really no reason for going beyond base R"
>>> >
>>> > I disagree. Lubridate is a fantastic package. I use it all the
>time. It
>>> > makes working with dates really easy, as evidenced by John Kane's
>>> > suggestion. I strongly recommend learning to work with it.
>>> >
>>> > The bottom line: as is often the case, there are many different
>ways to
>>> > accomplish a task in R.
>>>
>>> I apologise beforehand if this sparks an unnecessary discussion ;-)
>>>
>>> But the important point is:
>>> If you know the structure of the data you want to
>>> parse, then it is best to tell R (or any other language)
>>> this structure explicitly.
>>>
>>>
>>> > On Thu, Dec 19, 2019 at 10:31 AM Martin Maechler <
>>> maech...@stat.math.ethz.ch>
>>> > wrote:
>>> >
>>> >> > John Kane
>>> >> > on Tue, 17 Dec 2019 20:28:17 -0500 writes:
>>> >>
>>> >> > library(lubridate)
>>> >> > gs$dat1  <-  mdy(gs$date)
>>> >>
>>> >> there's really no reason for going beyond base R.
>>> >>
>>> >> Using the proper format as per Patrick and Peter's advice
>>> >> (below) is perfectly clear and actually
>>> >> more robust (for the next data set etc)
>>> >> than going via "good guessing" in extra packages.
>>> >>
>>> >> > On Tue, 17 Dec 2019 at 18:38, peter dalgaard
>
>>> >> wrote:
>>> >> >>
>>> >> >> ...and switch the order, and use %y for 2-digit years.
>>> >> >>
>>> >> >> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative)
><
>>> >> mal...@malonequantitative.com> wrote:
>>> >> >> >
>>> >> >> > Try putting / instead of - in your format, to match the
>data.
>>> >> >> >
>>> >> >> > On Tue, Dec 17, 2019 at 5:52 PM Val 
>>> wrote:
>>> >> >> >>
>>> >> >> >> Hi All,
>>> >> >> >>
>>> >> >> >> I wanted to to convert character date  mm/dd/yy  to
>>> -mm-dd
>>> >> >> >> The sample data and my attempt is shown below
>>> >> >> >>
>>> >> >> >> gs <-read.table(text="ID date
>>> >> >> >> A1   09/27/03
>>> >> >> >> A2   05/27/16
>>> >> >> >> A3   01/25/13
>>> >> >> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
>>> >> >> >>
>>> >> >> >> Desired output
>>> >> >> >>  ID date  d1
>>> >> >> >> A1 09/27/03 2003-09-27
>>> >> >> >> A2 05/27/16 2016-05-27
>>> >> >> >> A3 01/25/13 2012-04-25
>>> >> >> >> A4 09/27/19 2019-09-27
>>> >> >> >>
>>> >> >> >> I used this
>>> >> >> >> gs$d1 = as.Date(as.character(gs$date), format =
>"%Y-%m-%d")
>>> >> >> >>
>>> >> >> >> but I got NA's.
>>> >> >> >>
>>> >> >> >> How do I get my desired result?
>>> >> >> >> Thank you.
>>> >> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Peter Dalgaard, Professor,
>>> >> >> Center for Statistics, Copenhagen Business School
>>> >> >> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>>> >> >> Phone: (+45)38153501
>>> >> >> Office: A 4.23
>>> >> >> Email: 

Re: [R] How to convert ARMA process to infinite AR?

2019-12-19 Thread 傅强
Hi,

 AR<-c(.4,.45)

MA<-c(1,.25)

ARMAtoMA(ar =AR, ma = MA, lag.max = 30)

 

picoefs <- c(1, ARMAtoMA(ar = -MA, ma = -AR, lag.max = 30))

picoefs

Maybe it works!
[[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.


Re: [R] date

2019-12-19 Thread Eric Berger
[ ... taking the bait regarding the "unnecessary discussion" ... ]

The "Fortune nomination" that Bert sent includes the phrase

"...then it is best to tell R ..."

What metric is being used to do the ranking to get the "best"? If the
metric is related to "providing the most unambiguous information to R"
then I agree that providing the structure explicitly is best.
However, often what is "best" is to minimize programmer time. With
lubridate, I know that providing the clue 'ymd' is enough to have it
perform the date conversion correctly. That is minimal effort on my part,
which gives it a top ranking from my point of view.

Also, to broaden this "unnecessary discussion" I would argue that the
lubridate package may even be more "in the spirit of R" than what is being
proposed with the explicit structural information. Clearly R is far from
being a strongly typed language. If you really want to provide explicit
structural information maybe you would be better off with a language such
as C++. :-)





On Thu, Dec 19, 2019 at 2:30 PM Bert Gunter  wrote:

>
>
> "But the important point is:
> If you know the structure of the data you want to
> parse, then it is best to tell R (or any other language)
> this structure explicitly. "
>
> Fortune nomination!
>
> -- Bert
>
>
>
>
>
>
> Thu, Dec 19, 2019, 2:49 AM Enrico Schumann  wrote:
>
>>
>> Quoting Eric Berger :
>>
>> > Martin  writes: "there's really no reason for going beyond base R"
>> >
>> > I disagree. Lubridate is a fantastic package. I use it all the time. It
>> > makes working with dates really easy, as evidenced by John Kane's
>> > suggestion. I strongly recommend learning to work with it.
>> >
>> > The bottom line: as is often the case, there are many different ways to
>> > accomplish a task in R.
>>
>> I apologise beforehand if this sparks an unnecessary discussion ;-)
>>
>> But the important point is:
>> If you know the structure of the data you want to
>> parse, then it is best to tell R (or any other language)
>> this structure explicitly.
>>
>>
>> > On Thu, Dec 19, 2019 at 10:31 AM Martin Maechler <
>> maech...@stat.math.ethz.ch>
>> > wrote:
>> >
>> >> > John Kane
>> >> > on Tue, 17 Dec 2019 20:28:17 -0500 writes:
>> >>
>> >> > library(lubridate)
>> >> > gs$dat1  <-  mdy(gs$date)
>> >>
>> >> there's really no reason for going beyond base R.
>> >>
>> >> Using the proper format as per Patrick and Peter's advice
>> >> (below) is perfectly clear and actually
>> >> more robust (for the next data set etc)
>> >> than going via "good guessing" in extra packages.
>> >>
>> >> > On Tue, 17 Dec 2019 at 18:38, peter dalgaard 
>> >> wrote:
>> >> >>
>> >> >> ...and switch the order, and use %y for 2-digit years.
>> >> >>
>> >> >> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) <
>> >> mal...@malonequantitative.com> wrote:
>> >> >> >
>> >> >> > Try putting / instead of - in your format, to match the data.
>> >> >> >
>> >> >> > On Tue, Dec 17, 2019 at 5:52 PM Val 
>> wrote:
>> >> >> >>
>> >> >> >> Hi All,
>> >> >> >>
>> >> >> >> I wanted to to convert character date  mm/dd/yy  to
>> -mm-dd
>> >> >> >> The sample data and my attempt is shown below
>> >> >> >>
>> >> >> >> gs <-read.table(text="ID date
>> >> >> >> A1   09/27/03
>> >> >> >> A2   05/27/16
>> >> >> >> A3   01/25/13
>> >> >> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
>> >> >> >>
>> >> >> >> Desired output
>> >> >> >>  ID date  d1
>> >> >> >> A1 09/27/03 2003-09-27
>> >> >> >> A2 05/27/16 2016-05-27
>> >> >> >> A3 01/25/13 2012-04-25
>> >> >> >> A4 09/27/19 2019-09-27
>> >> >> >>
>> >> >> >> I used this
>> >> >> >> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
>> >> >> >>
>> >> >> >> but I got NA's.
>> >> >> >>
>> >> >> >> How do I get my desired result?
>> >> >> >> Thank you.
>> >> >> >>
>> >> >>
>> >> >> --
>> >> >> Peter Dalgaard, Professor,
>> >> >> Center for Statistics, Copenhagen Business School
>> >> >> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> >> >> Phone: (+45)38153501
>> >> >> Office: A 4.23
>> >> >> Email: pd@cbs.dk  Priv: pda...@gmail.com
>> >> >>
>> >>
>> >> > --
>> >> > John Kane
>> >> > Kingston ON Canada
>>
>>
>>
>> --
>> Enrico Schumann
>> Lucerne, Switzerland
>> http://enricoschumann.net
>>
>> __
>> 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.
>>
>>

[[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 

Re: [R] date

2019-12-19 Thread Bert Gunter
"But the important point is:
If you know the structure of the data you want to
parse, then it is best to tell R (or any other language)
this structure explicitly. "

Fortune nomination!

-- Bert






Thu, Dec 19, 2019, 2:49 AM Enrico Schumann  wrote:

>
> Quoting Eric Berger :
>
> > Martin  writes: "there's really no reason for going beyond base R"
> >
> > I disagree. Lubridate is a fantastic package. I use it all the time. It
> > makes working with dates really easy, as evidenced by John Kane's
> > suggestion. I strongly recommend learning to work with it.
> >
> > The bottom line: as is often the case, there are many different ways to
> > accomplish a task in R.
>
> I apologise beforehand if this sparks an unnecessary discussion ;-)
>
> But the important point is:
> If you know the structure of the data you want to
> parse, then it is best to tell R (or any other language)
> this structure explicitly.
>
>
> > On Thu, Dec 19, 2019 at 10:31 AM Martin Maechler <
> maech...@stat.math.ethz.ch>
> > wrote:
> >
> >> > John Kane
> >> > on Tue, 17 Dec 2019 20:28:17 -0500 writes:
> >>
> >> > library(lubridate)
> >> > gs$dat1  <-  mdy(gs$date)
> >>
> >> there's really no reason for going beyond base R.
> >>
> >> Using the proper format as per Patrick and Peter's advice
> >> (below) is perfectly clear and actually
> >> more robust (for the next data set etc)
> >> than going via "good guessing" in extra packages.
> >>
> >> > On Tue, 17 Dec 2019 at 18:38, peter dalgaard 
> >> wrote:
> >> >>
> >> >> ...and switch the order, and use %y for 2-digit years.
> >> >>
> >> >> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) <
> >> mal...@malonequantitative.com> wrote:
> >> >> >
> >> >> > Try putting / instead of - in your format, to match the data.
> >> >> >
> >> >> > On Tue, Dec 17, 2019 at 5:52 PM Val 
> wrote:
> >> >> >>
> >> >> >> Hi All,
> >> >> >>
> >> >> >> I wanted to to convert character date  mm/dd/yy  to -mm-dd
> >> >> >> The sample data and my attempt is shown below
> >> >> >>
> >> >> >> gs <-read.table(text="ID date
> >> >> >> A1   09/27/03
> >> >> >> A2   05/27/16
> >> >> >> A3   01/25/13
> >> >> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
> >> >> >>
> >> >> >> Desired output
> >> >> >>  ID date  d1
> >> >> >> A1 09/27/03 2003-09-27
> >> >> >> A2 05/27/16 2016-05-27
> >> >> >> A3 01/25/13 2012-04-25
> >> >> >> A4 09/27/19 2019-09-27
> >> >> >>
> >> >> >> I used this
> >> >> >> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
> >> >> >>
> >> >> >> but I got NA's.
> >> >> >>
> >> >> >> How do I get my desired result?
> >> >> >> Thank you.
> >> >> >>
> >> >>
> >> >> --
> >> >> Peter Dalgaard, Professor,
> >> >> Center for Statistics, Copenhagen Business School
> >> >> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >> >> Phone: (+45)38153501
> >> >> Office: A 4.23
> >> >> Email: pd@cbs.dk  Priv: pda...@gmail.com
> >> >>
> >>
> >> > --
> >> > John Kane
> >> > Kingston ON Canada
>
>
>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://enricoschumann.net
>
> __
> 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.
>
>

[[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.


Re: [R] date

2019-12-19 Thread Enrico Schumann



Quoting Eric Berger :


Martin  writes: "there's really no reason for going beyond base R"

I disagree. Lubridate is a fantastic package. I use it all the time. It
makes working with dates really easy, as evidenced by John Kane's
suggestion. I strongly recommend learning to work with it.

The bottom line: as is often the case, there are many different ways to
accomplish a task in R.


I apologise beforehand if this sparks an unnecessary discussion ;-)

But the important point is:
If you know the structure of the data you want to
parse, then it is best to tell R (or any other language)
this structure explicitly.



On Thu, Dec 19, 2019 at 10:31 AM Martin Maechler 
wrote:


> John Kane
> on Tue, 17 Dec 2019 20:28:17 -0500 writes:

> library(lubridate)
> gs$dat1  <-  mdy(gs$date)

there's really no reason for going beyond base R.

Using the proper format as per Patrick and Peter's advice
(below) is perfectly clear and actually
more robust (for the next data set etc)
than going via "good guessing" in extra packages.

> On Tue, 17 Dec 2019 at 18:38, peter dalgaard 
wrote:
>>
>> ...and switch the order, and use %y for 2-digit years.
>>
>> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) <
mal...@malonequantitative.com> wrote:
>> >
>> > Try putting / instead of - in your format, to match the data.
>> >
>> > On Tue, Dec 17, 2019 at 5:52 PM Val  wrote:
>> >>
>> >> Hi All,
>> >>
>> >> I wanted to to convert character date  mm/dd/yy  to -mm-dd
>> >> The sample data and my attempt is shown below
>> >>
>> >> gs <-read.table(text="ID date
>> >> A1   09/27/03
>> >> A2   05/27/16
>> >> A3   01/25/13
>> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
>> >>
>> >> Desired output
>> >>  ID date  d1
>> >> A1 09/27/03 2003-09-27
>> >> A2 05/27/16 2016-05-27
>> >> A3 01/25/13 2012-04-25
>> >> A4 09/27/19 2019-09-27
>> >>
>> >> I used this
>> >> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
>> >>
>> >> but I got NA's.
>> >>
>> >> How do I get my desired result?
>> >> Thank you.
>> >>
>>
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd@cbs.dk  Priv: pda...@gmail.com
>>

> --
> John Kane
> Kingston ON Canada




--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
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.


Re: [R] date

2019-12-19 Thread Eric Berger
Martin  writes: "there's really no reason for going beyond base R"

I disagree. Lubridate is a fantastic package. I use it all the time. It
makes working with dates really easy, as evidenced by John Kane's
suggestion. I strongly recommend learning to work with it.

The bottom line: as is often the case, there are many different ways to
accomplish a task in R.


On Thu, Dec 19, 2019 at 10:31 AM Martin Maechler 
wrote:

> > John Kane
> > on Tue, 17 Dec 2019 20:28:17 -0500 writes:
>
> > library(lubridate)
> > gs$dat1  <-  mdy(gs$date)
>
> there's really no reason for going beyond base R.
>
> Using the proper format as per Patrick and Peter's advice
> (below) is perfectly clear and actually
> more robust (for the next data set etc)
> than going via "good guessing" in extra packages.
>
> > On Tue, 17 Dec 2019 at 18:38, peter dalgaard 
> wrote:
> >>
> >> ...and switch the order, and use %y for 2-digit years.
> >>
> >> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) <
> mal...@malonequantitative.com> wrote:
> >> >
> >> > Try putting / instead of - in your format, to match the data.
> >> >
> >> > On Tue, Dec 17, 2019 at 5:52 PM Val  wrote:
> >> >>
> >> >> Hi All,
> >> >>
> >> >> I wanted to to convert character date  mm/dd/yy  to -mm-dd
> >> >> The sample data and my attempt is shown below
> >> >>
> >> >> gs <-read.table(text="ID date
> >> >> A1   09/27/03
> >> >> A2   05/27/16
> >> >> A3   01/25/13
> >> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
> >> >>
> >> >> Desired output
> >> >>  ID date  d1
> >> >> A1 09/27/03 2003-09-27
> >> >> A2 05/27/16 2016-05-27
> >> >> A3 01/25/13 2012-04-25
> >> >> A4 09/27/19 2019-09-27
> >> >>
> >> >> I used this
> >> >> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
> >> >>
> >> >> but I got NA's.
> >> >>
> >> >> How do I get my desired result?
> >> >> Thank you.
> >> >>
> >> >> __
> >> >> 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-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.
> >>
> >> --
> >> Peter Dalgaard, Professor,
> >> Center for Statistics, Copenhagen Business School
> >> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >> Phone: (+45)38153501
> >> Office: A 4.23
> >> Email: pd@cbs.dk  Priv: pda...@gmail.com
> >>
> >> __
> >> 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.
>
>
>
> > --
> > John Kane
> > Kingston ON Canada
>
> > __
> > 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-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.
>

[[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.


Re: [R] date

2019-12-19 Thread Martin Maechler
> John Kane 
> on Tue, 17 Dec 2019 20:28:17 -0500 writes:

> library(lubridate)
> gs$dat1  <-  mdy(gs$date)

there's really no reason for going beyond base R.

Using the proper format as per Patrick and Peter's advice
(below) is perfectly clear and actually
more robust (for the next data set etc)
than going via "good guessing" in extra packages.

> On Tue, 17 Dec 2019 at 18:38, peter dalgaard  wrote:
>> 
>> ...and switch the order, and use %y for 2-digit years.
>> 
>> > On 17 Dec 2019, at 23:57 , Patrick (Malone Quantitative) 
 wrote:
>> >
>> > Try putting / instead of - in your format, to match the data.
>> >
>> > On Tue, Dec 17, 2019 at 5:52 PM Val  wrote:
>> >>
>> >> Hi All,
>> >>
>> >> I wanted to to convert character date  mm/dd/yy  to -mm-dd
>> >> The sample data and my attempt is shown below
>> >>
>> >> gs <-read.table(text="ID date
>> >> A1   09/27/03
>> >> A2   05/27/16
>> >> A3   01/25/13
>> >> A4   09/27/19",header=TRUE,stringsAsFactors=F)
>> >>
>> >> Desired output
>> >>  ID date  d1
>> >> A1 09/27/03 2003-09-27
>> >> A2 05/27/16 2016-05-27
>> >> A3 01/25/13 2012-04-25
>> >> A4 09/27/19 2019-09-27
>> >>
>> >> I used this
>> >> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
>> >>
>> >> but I got NA's.
>> >>
>> >> How do I get my desired result?
>> >> Thank you.
>> >>
>> >> __
>> >> 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-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.
>> 
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd@cbs.dk  Priv: pda...@gmail.com
>> 
>> __
>> 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.



> -- 
> John Kane
> Kingston ON Canada

> __
> 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-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.