Re: [R] how to expand the dataframe

2016-07-21 Thread William Dunlap via R-help
Depending on your situation you may want all=TRUE, all.x=TRUE, or
all.y=TRUE.
I think the SQL people call these outer joins, left outer joins, and right
outer joins.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Jul 21, 2016 at 2:35 PM, lily li  wrote:

> I use this code, and it works. So has to set 'all=TRUE'.
>
> merge(df, data.frame(time=seq(as.Date("1990-01-01"),
> to=as.Date("1990-12-31"), by="days")), all=TRUE)
>
>
> On Thu, Jul 21, 2016 at 9:22 AM, Daniel Nordlund 
> wrote:
>
> > On 7/20/2016 8:26 PM, lily li wrote:
> >
> >> Yes, I tried to create a dataframe and merge it with the shortened
> >> dataframe. The resulting dataframe goes with the short one and truncates
> >> the complete date column, so it does not work.
> >>
> >> On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius <
> dwinsem...@comcast.net>
> >> wrote:
> >>
> >>
> >>> On Jul 20, 2016, at 1:31 PM, lily li  wrote:
> 
>  Hi R users,
> 
>  I have a dataframe, where there is a column 'time' represents time
>  series
>  but is not complete. How to expand the dataframe so this column will
> 
> >>> become
> >>>
>  complete, where other columns with the newly added rows have NA
> values?
>  Thanks.
> 
>  df
>  A B C time
>  105 3.3 1990-01-01
>  115  4 1990-02-07
>  124 3  1990-02-14
>  ...
> 
> >>>
> >>> Make a dataframe with a 'time' column using seq.Date and merge that
> >>> dataframe with your df dataframe.
> >>>
> >>>
>    [[alternative HTML version deleted]]
> 
> >>>
> >>> Really  isn't it time you learned how to send plain text. You've
> >>> posted many questions on Rhelp.  It's really not that difficult on
> >>> gmail. I
> >>> also have a gmail account and have had no difficulty finding
> instructions
> >>> on how to do it.
> >>>
> >>>
>  __
>  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 Winsemius
> >>> Alameda, CA, USA
> >>>
> >>>
> >>>
> >>
> > Don't just say you tried to do the merge and it doesn't work.  At a
> > minimum show us the ACTUAL code you used and give us any error messages
> you
> > got or show us a portion of the results and explain why it is not what
> you
> > expected.  If possible, give us a small amount of data using dput() so
> that
> > we can "play along at home" (i.e. give us a reproducible example).
> >
> > Dan
> >
> > Daniel Nordlund
> > Port Townsend, WA
> >
> >
> >
> > --
> > Daniel Noredlund
> > Bothell, WA USA
> >
> >
> > __
> > 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.
>

[[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] how to expand the dataframe

2016-07-21 Thread lily li
I use this code, and it works. So has to set 'all=TRUE'.

merge(df, data.frame(time=seq(as.Date("1990-01-01"),
to=as.Date("1990-12-31"), by="days")), all=TRUE)


On Thu, Jul 21, 2016 at 9:22 AM, Daniel Nordlund 
wrote:

> On 7/20/2016 8:26 PM, lily li wrote:
>
>> Yes, I tried to create a dataframe and merge it with the shortened
>> dataframe. The resulting dataframe goes with the short one and truncates
>> the complete date column, so it does not work.
>>
>> On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius 
>> wrote:
>>
>>
>>> On Jul 20, 2016, at 1:31 PM, lily li  wrote:

 Hi R users,

 I have a dataframe, where there is a column 'time' represents time
 series
 but is not complete. How to expand the dataframe so this column will

>>> become
>>>
 complete, where other columns with the newly added rows have NA values?
 Thanks.

 df
 A B C time
 105 3.3 1990-01-01
 115  4 1990-02-07
 124 3  1990-02-14
 ...

>>>
>>> Make a dataframe with a 'time' column using seq.Date and merge that
>>> dataframe with your df dataframe.
>>>
>>>
   [[alternative HTML version deleted]]

>>>
>>> Really  isn't it time you learned how to send plain text. You've
>>> posted many questions on Rhelp.  It's really not that difficult on
>>> gmail. I
>>> also have a gmail account and have had no difficulty finding instructions
>>> on how to do it.
>>>
>>>
 __
 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 Winsemius
>>> Alameda, CA, USA
>>>
>>>
>>>
>>
> Don't just say you tried to do the merge and it doesn't work.  At a
> minimum show us the ACTUAL code you used and give us any error messages you
> got or show us a portion of the results and explain why it is not what you
> expected.  If possible, give us a small amount of data using dput() so that
> we can "play along at home" (i.e. give us a reproducible example).
>
> Dan
>
> Daniel Nordlund
> Port Townsend, WA
>
>
>
> --
> Daniel Noredlund
> Bothell, WA USA
>
>
> __
> 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] how to expand the dataframe

2016-07-21 Thread Daniel Nordlund

On 7/20/2016 8:26 PM, lily li wrote:

Yes, I tried to create a dataframe and merge it with the shortened
dataframe. The resulting dataframe goes with the short one and truncates
the complete date column, so it does not work.

On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius 
wrote:




On Jul 20, 2016, at 1:31 PM, lily li  wrote:

Hi R users,

I have a dataframe, where there is a column 'time' represents time series
but is not complete. How to expand the dataframe so this column will

become

complete, where other columns with the newly added rows have NA values?
Thanks.

df
A B C time
105 3.3 1990-01-01
115  4 1990-02-07
124 3  1990-02-14
...


Make a dataframe with a 'time' column using seq.Date and merge that
dataframe with your df dataframe.



  [[alternative HTML version deleted]]


Really  isn't it time you learned how to send plain text. You've
posted many questions on Rhelp.  It's really not that difficult on gmail. I
also have a gmail account and have had no difficulty finding instructions
on how to do it.



__
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 Winsemius
Alameda, CA, USA






Don't just say you tried to do the merge and it doesn't work.  At a 
minimum show us the ACTUAL code you used and give us any error messages 
you got or show us a portion of the results and explain why it is not 
what you expected.  If possible, give us a small amount of data using 
dput() so that we can "play along at home" (i.e. give us a reproducible 
example).


Dan

Daniel Nordlund
Port Townsend, WA



--
Daniel Noredlund
Bothell, WA USA

__
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] how to expand the dataframe

2016-07-20 Thread William Dunlap via R-help
You need to show, not tell, what you did to get better answers.  Did you
use the all=TRUE argument to merge()?

> df <-
data.frame(A=c(10,11,12),B=c(5,5,4),C=c(3.3,4,3),time=as.Date(c("1990-01-01","1990-02-07","1990-02-14")))
0
> merge(df, data.frame(time=seq(as.Date("1990-01-01"),
to=as.Date("1990-02-15"), by="days")), all.y=TRUE)
 time  A  B   C
1  1990-01-01 10  5 3.3
2  1990-01-02 NA NA  NA
3  1990-01-03 NA NA  NA
...
36 1990-02-05 NA NA  NA
37 1990-02-06 NA NA  NA
38 1990-02-07 11  5 4.0
39 1990-02-08 NA NA  NA
...


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jul 20, 2016 at 8:26 PM, lily li  wrote:

> Yes, I tried to create a dataframe and merge it with the shortened
> dataframe. The resulting dataframe goes with the short one and truncates
> the complete date column, so it does not work.
>
> On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius 
> wrote:
>
> >
> > > On Jul 20, 2016, at 1:31 PM, lily li  wrote:
> > >
> > > Hi R users,
> > >
> > > I have a dataframe, where there is a column 'time' represents time
> series
> > > but is not complete. How to expand the dataframe so this column will
> > become
> > > complete, where other columns with the newly added rows have NA values?
> > > Thanks.
> > >
> > > df
> > > A B C time
> > > 105 3.3 1990-01-01
> > > 115  4 1990-02-07
> > > 124 3  1990-02-14
> > > ...
> >
> > Make a dataframe with a 'time' column using seq.Date and merge that
> > dataframe with your df dataframe.
> >
> > >
> > >   [[alternative HTML version deleted]]
> >
> > Really  isn't it time you learned how to send plain text. You've
> > posted many questions on Rhelp.  It's really not that difficult on
> gmail. I
> > also have a gmail account and have had no difficulty finding instructions
> > on how to do it.
> >
> > >
> > > __
> > > 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 Winsemius
> > Alameda, CA, USA
> >
> >
>
> [[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.


Re: [R] how to expand the dataframe

2016-07-20 Thread lily li
Yes, I tried to create a dataframe and merge it with the shortened
dataframe. The resulting dataframe goes with the short one and truncates
the complete date column, so it does not work.

On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius 
wrote:

>
> > On Jul 20, 2016, at 1:31 PM, lily li  wrote:
> >
> > Hi R users,
> >
> > I have a dataframe, where there is a column 'time' represents time series
> > but is not complete. How to expand the dataframe so this column will
> become
> > complete, where other columns with the newly added rows have NA values?
> > Thanks.
> >
> > df
> > A B C time
> > 105 3.3 1990-01-01
> > 115  4 1990-02-07
> > 124 3  1990-02-14
> > ...
>
> Make a dataframe with a 'time' column using seq.Date and merge that
> dataframe with your df dataframe.
>
> >
> >   [[alternative HTML version deleted]]
>
> Really  isn't it time you learned how to send plain text. You've
> posted many questions on Rhelp.  It's really not that difficult on gmail. I
> also have a gmail account and have had no difficulty finding instructions
> on how to do it.
>
> >
> > __
> > 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 Winsemius
> Alameda, CA, USA
>
>

[[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] how to expand the dataframe

2016-07-20 Thread David Winsemius

> On Jul 20, 2016, at 1:31 PM, lily li  wrote:
> 
> Hi R users,
> 
> I have a dataframe, where there is a column 'time' represents time series
> but is not complete. How to expand the dataframe so this column will become
> complete, where other columns with the newly added rows have NA values?
> Thanks.
> 
> df
> A B C time
> 105 3.3   1990-01-01
> 115  4 1990-02-07
> 124 3  1990-02-14
> ...

Make a dataframe with a 'time' column using seq.Date and merge that dataframe 
with your df dataframe.

> 
>   [[alternative HTML version deleted]]

Really  isn't it time you learned how to send plain text. You've posted 
many questions on Rhelp.  It's really not that difficult on gmail. I also have 
a gmail account and have had no difficulty finding instructions on how to do it.

> 
> __
> 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 Winsemius
Alameda, CA, USA

__
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] how to expand the dataframe

2016-07-20 Thread Jeff Newmiller
Look at the zoo or data.table packages. 
-- 
Sent from my phone. Please excuse my brevity.

On July 20, 2016 1:31:26 PM PDT, lily li  wrote:
>Hi R users,
>
>I have a dataframe, where there is a column 'time' represents time
>series
>but is not complete. How to expand the dataframe so this column will
>become
>complete, where other columns with the newly added rows have NA values?
>Thanks.
>
>df
>A B C time
>105 3.3   1990-01-01
>115  4 1990-02-07
>124 3  1990-02-14
>...
>
>   [[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-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] how to expand the dataframe

2016-07-20 Thread lily li
Hi R users,

I have a dataframe, where there is a column 'time' represents time series
but is not complete. How to expand the dataframe so this column will become
complete, where other columns with the newly added rows have NA values?
Thanks.

df
A B C time
105 3.3   1990-01-01
115  4 1990-02-07
124 3  1990-02-14
...

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