Stacking of vectors to form a column vector

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Stacking of vectors to form a column vector

Olufemi Bolarinwa
Hello,I am estimating a system of nonlinear equation where I need to stack my vector of y. I have data of about 6000units. I tried using the rbind but instead of having a vector of 1 by 18000, it is giving me a 3 by 6000 so that my matrix multiplication is non-conformable. The stack command requires an identifier but in this case, I do not have a unique identifier.
I would like to stack the the first 6000 units of y1 on the 2nd 6000 units of y2 and 6000 units of y3.
Any help will be greatly appreciated.
ThanksOlufemi

 

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Jeff Newmiller
Vectors are not "columns" or "rows". Use the c() function to concatenate vectors.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:

>Hello,I am estimating a system of nonlinear equation where I need to
>stack my vector of y. I have data of about 6000units. I tried using the
>rbind but instead of having a vector of 1 by 18000, it is giving me a 3
>by 6000 so that my matrix multiplication is non-conformable. The stack
>command requires an identifier but in this case, I do not have a unique
>identifier.
>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>units of y2 and 6000 units of y3.
>Any help will be greatly appreciated.
>ThanksOlufemi
>

>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Olufemi Bolarinwa
Thank you Jeff for your response.
My y1, y2, y3 are actually 3 columns in the data so I cannot use the c() function to concatenate them. I am confusing the "columns" with vectors. I actually meant columns.
Any help will be much appreciated
Olufemi 
 


     On Wednesday, 29 April 2015, 22:31, Jeff Newmiller <[hidden email]> wrote:
   

 Vectors are not "columns" or "rows". Use the c() function to concatenate vectors.
---------------------------------------------------------------------------
Jeff Newmiller                        The    .....      .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live Go...
                                      Live:  OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
/Software/Embedded Controllers)              .OO#.      .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.


> wrote:
>Hello,I am estimating a system of nonlinear equation where I need to
>stack my vector of y. I have data of about 6000units. I tried using the
>rbind but instead of having a vector of 1 by 18000, it is giving me a 3
>by 6000 so that my matrix multiplication is non-conformable. The stack
>command requires an identifier but in this case, I do not have a unique
>identifier.
>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>units of y2 and 6000 units of y3.
>Any help will be greatly appreciated.
>ThanksOlufemi
>

>
>    [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Jeff Newmiller
I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:

>Thank you Jeff for your response.
>My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>c() function to concatenate them. I am confusing the "columns" with
>vectors. I actually meant columns.
>Any help will be much appreciated
>Olufemi 
>
>
>
>On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
><[hidden email]> wrote:
>  
>
>Vectors are not "columns" or "rows". Use the c() function to
>concatenate vectors.
>---------------------------------------------------------------------------
>Jeff Newmiller                        The    .....      .....  Go
>Live...
>DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>Go...
>                                      Live:  OO#.. Dead: OO#..  Playing
>Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>/Software/Embedded Controllers)              .OO#.      .OO#. 
>rocks...1k
>---------------------------------------------------------------------------
>
>Sent from my phone. Please excuse my brevity.
>
>On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
><[hidden email]> wrote:
>>Hello,I am estimating a system of nonlinear equation where I need to
>>stack my vector of y. I have data of about 6000units. I tried using
>the
>>rbind but instead of having a vector of 1 by 18000, it is giving me a
>3
>>by 6000 so that my matrix multiplication is non-conformable. The stack
>>command requires an identifier but in this case, I do not have a
>unique
>>identifier.
>>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>units of y2 and 6000 units of y3.
>>Any help will be greatly appreciated.
>>ThanksOlufemi
>>
>> 
>>
>>    [[alternative HTML version deleted]]
>>
>>______________________________________________
>>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Jim Lemon-4
Hi Olufemi,
I sounds like you have a data frame (let's call it "mydata") with at
least three elements (columns). You may be trying to use c() in this
way:

y1to3<-c(y1,y2,y3)

in which case it won't work. However:

y1to3<-c(mydata$y1,mydata$y2,mydata$y3)

might do what you want, substituting whatever the name of your data
frame is for "mydata".

Jim


On Thu, Apr 30, 2015 at 1:20 PM, Jeff Newmiller
<[hidden email]> wrote:

> I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.
>
> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:
>>Thank you Jeff for your response.
>>My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>>c() function to concatenate them. I am confusing the "columns" with
>>vectors. I actually meant columns.
>>Any help will be much appreciated
>>Olufemi
>>
>>
>>
>>On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
>><[hidden email]> wrote:
>>
>>
>>Vectors are not "columns" or "rows". Use the c() function to
>>concatenate vectors.
>>---------------------------------------------------------------------------
>>Jeff Newmiller                        The    .....      .....  Go
>>Live...
>>DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>>Go...
>>                                      Live:  OO#.. Dead: OO#..  Playing
>>Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>>/Software/Embedded Controllers)              .OO#.      .OO#.
>>rocks...1k
>>---------------------------------------------------------------------------
>>
>>Sent from my phone. Please excuse my brevity.
>>
>>On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
>><[hidden email]> wrote:
>>>Hello,I am estimating a system of nonlinear equation where I need to
>>>stack my vector of y. I have data of about 6000units. I tried using
>>the
>>>rbind but instead of having a vector of 1 by 18000, it is giving me a
>>3
>>>by 6000 so that my matrix multiplication is non-conformable. The stack
>>>command requires an identifier but in this case, I do not have a
>>unique
>>>identifier.
>>>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>>units of y2 and 6000 units of y3.
>>>Any help will be greatly appreciated.
>>>ThanksOlufemi
>>>
>>>
>>>
>>>    [[alternative HTML version deleted]]
>>>
>>>______________________________________________
>>>[hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

MacQueen, Don
In reply to this post by Olufemi Bolarinwa
Here are two correct uses of the "stack command", if by that you mean the
stack() function.

> stack( data.frame(a=1:3, b=4:6, c=7:9) )
  values ind
1      1   a
2      2   a
3      3   a
4      4   b
5      5   b
6      6   b
7      7   c
8      8   c
9      9   c

> stack( list(a=1:3, b=4:6, c=7:9) )
  values ind
1      1   a
2      2   a
3      3   a
4      4   b
5      5   b
6      6   b
7      7   c
8      8   c
9      9   c

I would say that the "values" column of the output fits your description
of what you want to do. (though I used names a, b, c instead of y1, y2,
y3).

But without a reproducible example, one can't say for sure.



--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/29/15, 6:56 PM, "Olufemi Bolarinwa" <[hidden email]> wrote:

>Hello,I am estimating a system of nonlinear equation where I need to
>stack my vector of y. I have data of about 6000units. I tried using the
>rbind but instead of having a vector of 1 by 18000, it is giving me a 3
>by 6000 so that my matrix multiplication is non-conformable. The stack
>command requires an identifier but in this case, I do not have a unique
>identifier.
>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>units of y2 and 6000 units of y3.
>Any help will be greatly appreciated.
>ThanksOlufemi
>
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Bert Gunter
In reply to this post by Jim Lemon-4
... and if this is what is wanted, somewhat cleaner and more
generalizable for programming would be:

do.call(c, mydata[,1:3])

## where the column indices might have to be adjusted to get the
desired columns.

Cheers,

Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Wed, Apr 29, 2015 at 11:51 PM, Jim Lemon <[hidden email]> wrote:

> Hi Olufemi,
> I sounds like you have a data frame (let's call it "mydata") with at
> least three elements (columns). You may be trying to use c() in this
> way:
>
> y1to3<-c(y1,y2,y3)
>
> in which case it won't work. However:
>
> y1to3<-c(mydata$y1,mydata$y2,mydata$y3)
>
> might do what you want, substituting whatever the name of your data
> frame is for "mydata".
>
> Jim
>
>
> On Thu, Apr 30, 2015 at 1:20 PM, Jeff Newmiller
> <[hidden email]> wrote:
>> I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.
>>
>> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>> ---------------------------------------------------------------------------
>> Jeff Newmiller                        The     .....       .....  Go Live...
>> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
>>                                       Live:   OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>> ---------------------------------------------------------------------------
>> Sent from my phone. Please excuse my brevity.
>>
>> On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:
>>>Thank you Jeff for your response.
>>>My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>>>c() function to concatenate them. I am confusing the "columns" with
>>>vectors. I actually meant columns.
>>>Any help will be much appreciated
>>>Olufemi
>>>
>>>
>>>
>>>On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
>>><[hidden email]> wrote:
>>>
>>>
>>>Vectors are not "columns" or "rows". Use the c() function to
>>>concatenate vectors.
>>>---------------------------------------------------------------------------
>>>Jeff Newmiller                        The    .....      .....  Go
>>>Live...
>>>DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>>>Go...
>>>                                      Live:  OO#.. Dead: OO#..  Playing
>>>Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>>>/Software/Embedded Controllers)              .OO#.      .OO#.
>>>rocks...1k
>>>---------------------------------------------------------------------------
>>>
>>>Sent from my phone. Please excuse my brevity.
>>>
>>>On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
>>><[hidden email]> wrote:
>>>>Hello,I am estimating a system of nonlinear equation where I need to
>>>>stack my vector of y. I have data of about 6000units. I tried using
>>>the
>>>>rbind but instead of having a vector of 1 by 18000, it is giving me a
>>>3
>>>>by 6000 so that my matrix multiplication is non-conformable. The stack
>>>>command requires an identifier but in this case, I do not have a
>>>unique
>>>>identifier.
>>>>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>>>units of y2 and 6000 units of y3.
>>>>Any help will be greatly appreciated.
>>>>ThanksOlufemi
>>>>
>>>>
>>>>
>>>>    [[alternative HTML version deleted]]
>>>>
>>>>______________________________________________
>>>>[hidden email] 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.
>>
>> ______________________________________________
>> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Marc Schwartz-3
Hi,

Given that a data frame is a list:

  unlist(mydata[, 1:3])

For example:

> all(unlist(iris[, 1:3]) == do.call(c, iris[, 1:3]))
[1] TRUE


Also, note that the returned result in both cases above retains names:

> unlist(iris[, 1:3])
  Sepal.Length1   Sepal.Length2   Sepal.Length3   Sepal.Length4
            5.1             4.9             4.7             4.6
  Sepal.Length5   Sepal.Length6   Sepal.Length7   Sepal.Length8
            5.0             5.4             4.6             5.0
  Sepal.Length9  Sepal.Length10  Sepal.Length11  Sepal.Length12
            4.4             4.9             5.4             4.8
...

You can just get the plain vector by using:

> unlist(iris[, 1:3], use.names = FALSE)
  [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7
 [17] 5.4 5.1 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4
 [33] 5.2 5.5 4.9 5.0 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6
 [49] 5.3 5.0 7.0 6.4 6.9 5.5 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1
...


As Bert notes, the indices would need to be adjusted for the actual data frame in question.

Regards,

Marc



> On Apr 30, 2015, at 10:52 AM, Bert Gunter <[hidden email]> wrote:
>
> ... and if this is what is wanted, somewhat cleaner and more
> generalizable for programming would be:
>
> do.call(c, mydata[,1:3])
>
> ## where the column indices might have to be adjusted to get the
> desired columns.
>
> Cheers,
>
> Bert
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Clifford Stoll
>
>
>
>
> On Wed, Apr 29, 2015 at 11:51 PM, Jim Lemon <[hidden email]> wrote:
>> Hi Olufemi,
>> I sounds like you have a data frame (let's call it "mydata") with at
>> least three elements (columns). You may be trying to use c() in this
>> way:
>>
>> y1to3<-c(y1,y2,y3)
>>
>> in which case it won't work. However:
>>
>> y1to3<-c(mydata$y1,mydata$y2,mydata$y3)
>>
>> might do what you want, substituting whatever the name of your data
>> frame is for "mydata".
>>
>> Jim
>>
>>
>> On Thu, Apr 30, 2015 at 1:20 PM, Jeff Newmiller
>> <[hidden email]> wrote:
>>> I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.
>>>
>>> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>>> ---------------------------------------------------------------------------
>>> Jeff Newmiller                        The     .....       .....  Go Live...
>>> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
>>>                                      Live:   OO#.. Dead: OO#..  Playing
>>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>>> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>>> ---------------------------------------------------------------------------
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:
>>>> Thank you Jeff for your response.
>>>> My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>>>> c() function to concatenate them. I am confusing the "columns" with
>>>> vectors. I actually meant columns.
>>>> Any help will be much appreciated
>>>> Olufemi
>>>>
>>>>
>>>>
>>>> On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
>>>> <[hidden email]> wrote:
>>>>
>>>>
>>>> Vectors are not "columns" or "rows". Use the c() function to
>>>> concatenate vectors.
>>>> ---------------------------------------------------------------------------
>>>> Jeff Newmiller                        The    .....      .....  Go
>>>> Live...
>>>> DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>>>> Go...
>>>>                                     Live:  OO#.. Dead: OO#..  Playing
>>>> Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>>>> /Software/Embedded Controllers)              .OO#.      .OO#.
>>>> rocks...1k
>>>> ---------------------------------------------------------------------------
>>>>
>>>> Sent from my phone. Please excuse my brevity.
>>>>
>>>> On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
>>>> <[hidden email]> wrote:
>>>>> Hello,I am estimating a system of nonlinear equation where I need to
>>>>> stack my vector of y. I have data of about 6000units. I tried using
>>>> the
>>>>> rbind but instead of having a vector of 1 by 18000, it is giving me a
>>>> 3
>>>>> by 6000 so that my matrix multiplication is non-conformable. The stack
>>>>> command requires an identifier but in this case, I do not have a
>>>> unique
>>>>> identifier.
>>>>> I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>>>> units of y2 and 6000 units of y3.
>>>>> Any help will be greatly appreciated.
>>>>> ThanksOlufemi

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Olufemi Bolarinwa
In reply to this post by Bert Gunter
Thank you. your suggestions all worked.
Best Regards 
 


     On Thursday, 30 April 2015, 11:52, Bert Gunter <[hidden email]> wrote:
   

 ... and if this is what is wanted, somewhat cleaner and more
generalizable for programming would be:

do.call(c, mydata[,1:3])

## where the column indices might have to be adjusted to get the
desired columns.

Cheers,

Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Wed, Apr 29, 2015 at 11:51 PM, Jim Lemon <[hidden email]> wrote:

> Hi Olufemi,
> I sounds like you have a data frame (let's call it "mydata") with at
> least three elements (columns). You may be trying to use c() in this
> way:
>
> y1to3<-c(y1,y2,y3)
>
> in which case it won't work. However:
>
> y1to3<-c(mydata$y1,mydata$y2,mydata$y3)
>
> might do what you want, substituting whatever the name of your data
> frame is for "mydata".
>
> Jim
>
>
> On Thu, Apr 30, 2015 at 1:20 PM, Jeff Newmiller
> <[hidden email]> wrote:
>> I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.
>>
>> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>> ---------------------------------------------------------------------------
>> Jeff Newmiller                        The    .....      .....  Go Live...
>> DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live Go...
>>                                      Live:  OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>> /Software/Embedded Controllers)              .OO#.      .OO#.  rocks...1k
>> ---------------------------------------------------------------------------
>> Sent from my phone. Please excuse my brevity.
>>
>> On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:
>>>Thank you Jeff for your response.
>>>My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>>>c() function to concatenate them. I am confusing the "columns" with
>>>vectors. I actually meant columns.
>>>Any help will be much appreciated
>>>Olufemi
>>>
>>>
>>>
>>>On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
>>><[hidden email]> wrote:
>>>
>>>
>>>Vectors are not "columns" or "rows". Use the c() function to
>>>concatenate vectors.
>>>---------------------------------------------------------------------------
>>>Jeff Newmiller                        The    .....      .....  Go
>>>Live...
>>>DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>>>Go...
>>>                                      Live:  OO#.. Dead: OO#..  Playing
>>>Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>>>/Software/Embedded Controllers)              .OO#.      .OO#.
>>>rocks...1k
>>>---------------------------------------------------------------------------
>>>
>>>Sent from my phone. Please excuse my brevity.
>>>
>>>On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
>>><[hidden email]> wrote:
>>>>Hello,I am estimating a system of nonlinear equation where I need to
>>>>stack my vector of y. I have data of about 6000units. I tried using
>>>the
>>>>rbind but instead of having a vector of 1 by 18000, it is giving me a
>>>3
>>>>by 6000 so that my matrix multiplication is non-conformable. The stack
>>>>command requires an identifier but in this case, I do not have a
>>>unique
>>>>identifier.
>>>>I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>>>units of y2 and 6000 units of y3.
>>>>Any help will be greatly appreciated.
>>>>ThanksOlufemi
>>>>
>>>>
>>>>
>>>>    [[alternative HTML version deleted]]
>>>>
>>>>______________________________________________
>>>>[hidden email] 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.
>>
>> ______________________________________________
>> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking of vectors to form a column vector

Bert Gunter
In reply to this post by Marc Schwartz-3
Yes, I think unlist() is still better.

One caution (for all): make sure the columns are all of the same
type/class/mode or you may be in for nasty surprises.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Thu, Apr 30, 2015 at 9:32 AM, Marc Schwartz <[hidden email]> wrote:

> Hi,
>
> Given that a data frame is a list:
>
>   unlist(mydata[, 1:3])
>
> For example:
>
>> all(unlist(iris[, 1:3]) == do.call(c, iris[, 1:3]))
> [1] TRUE
>
>
> Also, note that the returned result in both cases above retains names:
>
>> unlist(iris[, 1:3])
>   Sepal.Length1   Sepal.Length2   Sepal.Length3   Sepal.Length4
>             5.1             4.9             4.7             4.6
>   Sepal.Length5   Sepal.Length6   Sepal.Length7   Sepal.Length8
>             5.0             5.4             4.6             5.0
>   Sepal.Length9  Sepal.Length10  Sepal.Length11  Sepal.Length12
>             4.4             4.9             5.4             4.8
> ...
>
> You can just get the plain vector by using:
>
>> unlist(iris[, 1:3], use.names = FALSE)
>   [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7
>  [17] 5.4 5.1 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4
>  [33] 5.2 5.5 4.9 5.0 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6
>  [49] 5.3 5.0 7.0 6.4 6.9 5.5 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1
> ...
>
>
> As Bert notes, the indices would need to be adjusted for the actual data frame in question.
>
> Regards,
>
> Marc
>
>
>
>> On Apr 30, 2015, at 10:52 AM, Bert Gunter <[hidden email]> wrote:
>>
>> ... and if this is what is wanted, somewhat cleaner and more
>> generalizable for programming would be:
>>
>> do.call(c, mydata[,1:3])
>>
>> ## where the column indices might have to be adjusted to get the
>> desired columns.
>>
>> Cheers,
>>
>> Bert
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>> (650) 467-7374
>>
>> "Data is not information. Information is not knowledge. And knowledge
>> is certainly not wisdom."
>> Clifford Stoll
>>
>>
>>
>>
>> On Wed, Apr 29, 2015 at 11:51 PM, Jim Lemon <[hidden email]> wrote:
>>> Hi Olufemi,
>>> I sounds like you have a data frame (let's call it "mydata") with at
>>> least three elements (columns). You may be trying to use c() in this
>>> way:
>>>
>>> y1to3<-c(y1,y2,y3)
>>>
>>> in which case it won't work. However:
>>>
>>> y1to3<-c(mydata$y1,mydata$y2,mydata$y3)
>>>
>>> might do what you want, substituting whatever the name of your data
>>> frame is for "mydata".
>>>
>>> Jim
>>>
>>>
>>> On Thu, Apr 30, 2015 at 1:20 PM, Jeff Newmiller
>>> <[hidden email]> wrote:
>>>> I am sure you can use c() because columns may be vectors even though vectors are not columns, but you really need to follow the posting guide and provide a reproducible example for us to show you how. You might find [1] helpful, in particular as it describes the use of the dput function to give us a few rows of your data.
>>>>
>>>> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>>>> ---------------------------------------------------------------------------
>>>> Jeff Newmiller                        The     .....       .....  Go Live...
>>>> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
>>>>                                      Live:   OO#.. Dead: OO#..  Playing
>>>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>>>> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>>>> ---------------------------------------------------------------------------
>>>> Sent from my phone. Please excuse my brevity.
>>>>
>>>> On April 29, 2015 7:48:24 PM PDT, Olufemi Bolarinwa <[hidden email]> wrote:
>>>>> Thank you Jeff for your response.
>>>>> My y1, y2, y3 are actually 3 columns in the data so I cannot use the
>>>>> c() function to concatenate them. I am confusing the "columns" with
>>>>> vectors. I actually meant columns.
>>>>> Any help will be much appreciated
>>>>> Olufemi
>>>>>
>>>>>
>>>>>
>>>>> On Wednesday, 29 April 2015, 22:31, Jeff Newmiller
>>>>> <[hidden email]> wrote:
>>>>>
>>>>>
>>>>> Vectors are not "columns" or "rows". Use the c() function to
>>>>> concatenate vectors.
>>>>> ---------------------------------------------------------------------------
>>>>> Jeff Newmiller                        The    .....      .....  Go
>>>>> Live...
>>>>> DCN:<[hidden email]>        Basics: ##.#.      ##.#.  Live
>>>>> Go...
>>>>>                                     Live:  OO#.. Dead: OO#..  Playing
>>>>> Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
>>>>> /Software/Embedded Controllers)              .OO#.      .OO#.
>>>>> rocks...1k
>>>>> ---------------------------------------------------------------------------
>>>>>
>>>>> Sent from my phone. Please excuse my brevity.
>>>>>
>>>>> On April 29, 2015 6:56:46 PM PDT, Olufemi Bolarinwa
>>>>> <[hidden email]> wrote:
>>>>>> Hello,I am estimating a system of nonlinear equation where I need to
>>>>>> stack my vector of y. I have data of about 6000units. I tried using
>>>>> the
>>>>>> rbind but instead of having a vector of 1 by 18000, it is giving me a
>>>>> 3
>>>>>> by 6000 so that my matrix multiplication is non-conformable. The stack
>>>>>> command requires an identifier but in this case, I do not have a
>>>>> unique
>>>>>> identifier.
>>>>>> I would like to stack the the first 6000 units of y1 on the 2nd 6000
>>>>>> units of y2 and 6000 units of y3.
>>>>>> Any help will be greatly appreciated.
>>>>>> ThanksOlufemi
>

______________________________________________
[hidden email] 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.