Concatenation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Concatenation

santana sarma
  Hi,

I have a dataframe with some 800 rows and 14 columns.

Could you please advise how I can concatenate the rows - one after another.
Similarly for columns, one below the other.

Many thanks.

Cheers,
Santana

        [[alternative HTML version deleted]]

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

Re: Concatenation

David Winsemius

On May 20, 2010, at 11:05 PM, santana sarma wrote:

>  Hi,
>
> I have a dataframe with some 800 rows and 14 columns.
>
> Could you please advise how I can concatenate the rows - one after  
> another.
> Similarly for columns, one below the other.

Not sure exactly what you are after:

unlist might accomplish the second task.

Whether c(apply(df, 1, I)) would be satisfactory for the first task  
might depend on whether the columns in the dataframe were all of the  
same type. Now that I think of it, both soolutions would force the  
types to be that same.

?"c"
?I
?apply

df[1:nrow(df), ]   ...  would essentially give you the first request,  
but it would not be any different than just typing df. So .... what do  
intend this process to accomplish?

--

David Winsemius, MD
West Hartford, CT

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

Re: Concatenation

santana sarma
Hi David,

SORRY - I am trying to be more clearer this time.

Let's say the dataframe has some rows and columns, with unique rownames and
column names. The rest of the data in the dataframe are just numbers.

I wish to concatenate those rows. That means : I wish to concatenate first
10 rows' values in one row, then next 20 rows's values in the next row ....
and so on.

Similarly, for columns : The first 10 column's values will be one below the
other ... and so on.

Cheers,


= = = = = = = = =  = =


On Fri, May 21, 2010 at 3:53 PM, David Winsemius <[hidden email]>wrote:

>
> On May 20, 2010, at 11:05 PM, santana sarma wrote:
>
>  Hi,
>>
>> I have a dataframe with some 800 rows and 14 columns.
>>
>> Could you please advise how I can concatenate the rows - one after
>> another.
>> Similarly for columns, one below the other.
>>
>
> Not sure exactly what you are after:
>
> unlist might accomplish the second task.
>
> Whether c(apply(df, 1, I)) would be satisfactory for the first task might
> depend on whether the columns in the dataframe were all of the same type.
> Now that I think of it, both soolutions would force the types to be that
> same.
>
> ?"c"
> ?I
> ?apply
>
> df[1:nrow(df), ]   ...  would essentially give you the first request, but
> it would not be any different than just typing df. So .... what do intend
> this process to accomplish?
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>

        [[alternative HTML version deleted]]

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

Re: Concatenation

Shi, Tao
Still not clear.  Follow the posting guide and some examples always help.  

Not sure how you "concatenate" numbers?

You can try, for example,

apply(df[1:10,], 2, paste, collapse=" ")

but this will turn everything into strings.  Is this what you want?

..Tao




----- Original Message ----
> From: santana sarma <[hidden email]>
> To: David Winsemius <[hidden email]>
> Cc: [hidden email]
> Sent: Thu, May 20, 2010 9:21:33 PM
> Subject: Re: [R] Concatenation
>
> Hi David,

SORRY - I am trying to be more clearer this time.

Let's
> say the dataframe has some rows and columns, with unique rownames and
column
> names. The rest of the data in the dataframe are just numbers.

I wish to
> concatenate those rows. That means : I wish to concatenate first
10 rows'
> values in one row, then next 20 rows's values in the next row ....
and so
> on.

Similarly, for columns : The first 10 column's values will be one
> below the
other ... and so on.

Cheers,


= = = = = = = =
> =  = =


On Fri, May 21, 2010 at 3:53 PM, David Winsemius <
> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]>wrote:

>
>
> On May 20, 2010, at 11:05 PM, santana sarma wrote:
>
>  
> Hi,
>>
>> I have a dataframe with some 800 rows and 14
> columns.
>>
>> Could you please advise how I can concatenate
> the rows - one after
>> another.
>> Similarly for columns, one
> below the other.
>>
>
> Not sure exactly what you are
> after:
>
> unlist might accomplish the second task.
>
>
> Whether c(apply(df, 1, I)) would be satisfactory for the first task
> might
> depend on whether the columns in the dataframe were all of the
> same type.
> Now that I think of it, both soolutions would force the types
> to be that
> same.
>
> ?"c"
> ?I
>
> ?apply
>
> df[1:nrow(df), ]   ...  would essentially give
> you the first request, but
> it would not be any different than just
> typing df. So .... what do intend
> this process to
> accomplish?
>
> --
>
> David Winsemius, MD
> West
> Hartford, CT
>
>

    [[alternative HTML
> version deleted]]

______________________________________________

> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email] mailing list

> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >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
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: Concatenation

santana sarma
Ok -let's forget about the dataframe.

Say, I have this (huge) spreadsheet that has some rows and columns, with
unique rownames and column names.

Using R, I wish to FINALLY have a spreadsheet where the values of the
first 10 rows remain in a single row. And, the values of the next 10 rows
remain in the next row .... and so on.

Example:

row1 = 2, 3.4, 5, 6
row2 = 3, 4.3, 0, 2
.......
row 10 = 1,3, 4, 5

new_row_should_be_like = 2, 3.4, 5, 6, 3, 4.3, 0, 2, ...... 1, 3, 4, 5


Similarly,

Similarly, for columns, the new spreadsheet should FINALLY contain : the
values of the columns coming one below the other (i.e., resulting in a
single column, without the identifiers).

col1   col2   col3......... col10
2       3         4                5
1       2         5                0
...........
...........

new_column_should_be_like =
2
1
...
3
2
....
4
5
...
5
0
.....
......



Cheers,


= = = === = = = = =


On Fri, May 21, 2010 at 5:51 PM, Shi, Tao <[hidden email]> wrote:

> Still not clear.  Follow the posting guide and some examples always help.
>
> Not sure how you "concatenate" numbers?
>
> You can try, for example,
>
> apply(df[1:10,], 2, paste, collapse=" ")
>
> but this will turn everything into strings.  Is this what you want?
>
> ..Tao
>
>
>
>
> ----- Original Message ----
> > From: santana sarma <[hidden email]>
> > To: David Winsemius <[hidden email]>
> > Cc: [hidden email]
> > Sent: Thu, May 20, 2010 9:21:33 PM
> > Subject: Re: [R] Concatenation
> >
> > Hi David,
>
> SORRY - I am trying to be more clearer this time.
>
> Let's
> > say the dataframe has some rows and columns, with unique rownames and
> column
> > names. The rest of the data in the dataframe are just numbers.
>
> I wish to
> > concatenate those rows. That means : I wish to concatenate first
> 10 rows'
> > values in one row, then next 20 rows's values in the next row ....
> and so
> > on.
>
> Similarly, for columns : The first 10 column's values will be one
> > below the
> other ... and so on.
>
> Cheers,
>
>
> = = = = = = = =
> > =  = =
>
>
> On Fri, May 21, 2010 at 3:53 PM, David Winsemius <
> > ymailto="mailto:[hidden email]"
> > href="mailto:[hidden email]">[hidden email]>wrote:
>
> >
> >
> > On May 20, 2010, at 11:05 PM, santana sarma wrote:
> >
> >
> > Hi,
> >>
> >> I have a dataframe with some 800 rows and 14
> > columns.
> >>
> >> Could you please advise how I can concatenate
> > the rows - one after
> >> another.
> >> Similarly for columns, one
> > below the other.
> >>
> >
> > Not sure exactly what you are
> > after:
> >
> > unlist might accomplish the second task.
> >
> >
> > Whether c(apply(df, 1, I)) would be satisfactory for the first task
> > might
> > depend on whether the columns in the dataframe were all of the
> > same type.
> > Now that I think of it, both soolutions would force the types
> > to be that
> > same.
> >
> > ?"c"
> > ?I
> >
> > ?apply
> >
> > df[1:nrow(df), ]   ...  would essentially give
> > you the first request, but
> > it would not be any different than just
> > typing df. So .... what do intend
> > this process to
> > accomplish?
> >
> > --
> >
> > David Winsemius, MD
> > West
> > Hartford, CT
> >
> >
>
>     [[alternative HTML
> > version deleted]]
>
> ______________________________________________
>
> > ymailto="mailto:[hidden email]"
> > href="mailto:[hidden email]">[hidden email] mailing list
>
> > href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> > >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
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: Concatenation

Shi, Tao
Well, it seems a simple "c" will do.

e.g.

df <- matrix(rnorm(100), ncol=4)
c(t(df[1:10,]))  # concatenate rows

c(df)  # concatenate columns






>
>From: santana sarma <[hidden email]>
>To: "Shi, Tao" <[hidden email]>; [hidden email]
>Sent: Thu, May 20, 2010 11:45:25 PM
>Subject: Re: Concatenation
>
>
>Ok -let's forget about the dataframe.
>
>
>Say, I have this (huge) spreadsheet that has some rows and columns, with unique rownames and column names.
>
>Using R, I wish to FINALLY have a spreadsheet where the values of the first 10 rows remain in a single row. And, the values of the next 10 rows remain in the next row .... and so on.
>
>
>Example:
>
>
>row1 = 2, 3.4, 5, 6
>row2 = 3, 4.3, 0, 2
>.......
>row 10 = 1,3, 4, 5
>
>
>new_row_should_be_like = 2, 3.4, 5, 6, 3, 4.3, 0, 2, ...... 1, 3, 4, 5  
>
>
>
>
>Similarly,
>
>Similarly, for columns, the new spreadsheet should FINALLY contain : the values of the columns coming one below the other (i.e., resulting in a single column, without the identifiers).
>
>
>col1   col2   col3......... col10
>2       3         4                5
>1       2         5                0
>...........
>...........
>
>
>new_column_should_be_like =
>2
>1
>...
>3
>2
>....
>4
>5
>...
>5
>0  
>.....
>......
>
>
>
>
>
>
>Cheers,
>
>
>
>
>= = = === = = = = =
>
>
>On Fri, May 21, 2010 at 5:51 PM, Shi, Tao <[hidden email]> wrote:
>
>Still not clear.  Follow the posting guide and some examples always help.
>>
>>>>Not sure how you "concatenate" numbers?
>>
>>>>You can try, for example,
>>
>>>>apply(df[1:10,], 2, paste, collapse=" ")
>>
>>>>but this will turn everything into strings.  Is this what you want?
>>
>>>>..Tao
>>
>>
>>
>>
>>
>>>>----- Original Message ----
>>>>> From: santana sarma <[hidden email]>
>>>>> To: David Winsemius <[hidden email]>
>>>>> Cc: [hidden email]
>>>>> Sent: Thu, May 20, 2010 9:21:33 PM
>>>>> Subject: Re: [R] Concatenation
>>>>>
>>>>> Hi David,
>>
>>>>SORRY - I am trying to be more clearer this time.
>>
>>>>Let's
>>>>> say the dataframe has some rows and columns, with unique rownames and
>>>>column
>>>>> names. The rest of the data in the dataframe are just numbers.
>>
>>>>I wish to
>>>>> concatenate those rows. That means : I wish to concatenate first
>>>>10 rows'
>>>>> values in one row, then next 20 rows's values in the next row ....
>>>>and so
>>>>> on.
>>
>>>>Similarly, for columns : The first 10 column's values will be one
>>>>> below the
>>>>other ... and so on.
>>
>>>>Cheers,
>>
>>
>>>>= = = = = = = =
>>>>> =  = =
>>
>>
>>>>On Fri, May 21, 2010 at 3:53 PM, David Winsemius <
>>> ymailto="mailto:[hidden email]"
>>>>> href="mailto:[hidden email]">[hidden email]>wrote:
>>
>>
>>>>>
>>>>>
>>>>> On May 20, 2010, at 11:05 PM, santana sarma wrote:
>>>>>
>>>>>
>>>>> Hi,
>>>>>>
>>>>>> I have a dataframe with some 800 rows and 14
>>>>> columns.
>>>>>>
>>>>>> Could you please advise how I can concatenate
>>>>> the rows - one after
>>>>>> another.
>>>>>> Similarly for columns, one
>>>>> below the other.
>>>>>>
>>>>>
>>>>> Not sure exactly what you are
>>>>> after:
>>>>>
>>>>> unlist might accomplish the second task.
>>>>>
>>>>>
>>>>> Whether c(apply(df, 1, I)) would be satisfactory for the first task
>>>>> might
>>>>> depend on whether the columns in the dataframe were all of the
>>>>> same type.
>>>>> Now that I think of it, both soolutions would force the types
>>>>> to be that
>>>>> same.
>>>>>
>>>>> ?"c"
>>>>> ?I
>>>>>
>>>>> ?apply
>>>>>
>>>>> df[1:nrow(df), ]   ...  would essentially give
>>>>> you the first request, but
>>>>> it would not be any different than just
>>>>> typing df. So .... what do intend
>>>>> this process to
>>>>> accomplish?
>>>>>
>>>>> --
>>>>>
>>>>> David Winsemius, MD
>>>>> West
>>>>> Hartford, CT
>>>>>
>>>>>
>>
>>
   [[alternative HTML

>>>>> version deleted]]
>>
>>>>______________________________________________
>>
>>>>> ymailto="mailto:[hidden email]"
>>>>> href="mailto:[hidden email]">[hidden email] mailing list
>>
>>>>> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
>>>>> >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
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: Concatenation

Wu Gong
In reply to this post by santana sarma
Try resequence or rematrix


olddata <- data.frame(matrix(rnorm(200), nrow=40))
newdata <- data.frame(matrix(as.vector(t(olddata)), nrow=nrow(olddata)/10))
dim(olddata)
dim(newdata)
Reply | Threaded
Open this post in threaded view
|

Re: Concatenation

Wu Gong
In reply to this post by santana sarma
Sorry, I made a mistake. Should add "byrow = TRUE".
Using randomly created values can't check the result, a sequence will be better.

olddata <- data.frame(matrix(1:200, nrow=40, byrow = TRUE))
newdata <- data.frame(matrix(as.vector(t(olddata)), nrow=nrow(olddata)/10,byrow = TRUE))
dim(olddata)
dim(newdata)
olddata[1:2,]
newdata[1:2,]
Reply | Threaded
Open this post in threaded view
|

weighted regression in drc package

array chip
Hi, I am currently trying to do dose-response curves
using weighted 4-parameter model (4PL). The weighting was based on
1/(expected variance) derived from historical data. I tried both drm() from drc package, and nls(), found very different
results derived from drm() vs. nls() using "weights=" argument.

d1<-read.table("d1.txt",sep='\t',header=T,row.names=1)

drm(y~x,weights=1/exp((-1.8286)+0.05481*y-0.000405225*(y-48.34177)^2),data = d1,fct = LL.4(),control=drmc(relTol=1e-12))
b:(Intercept)  c:(Intercept)  d:(Intercept)  e:(Intercept)  
      -1.5859         0.7823        47.3591        38.7717

nls(y~c+(d-c)/(1+(x/e)^b),weights=1/exp((-1.8286)+0.05481*y-0.000405225*(y-48.34177)^2),data=d1,
start=list(b=-1, c =0, d=100, e=150))
       b        c        d        e
-1.0076  -0.1143 104.9470 152.5558

But if I run unweighted dose-response curve, both drm() and nls() gave the same results:

drm(y~x,data = d1,fct = LL.4(),control=drmc(relTol=1e-12))
b:(Intercept)  c:(Intercept)  d:(Intercept)  e:(Intercept)  
      -1.1416         0.6986       102.8613       135.9371

nls(y~c+(d-c)/(1+(x/e)^b),data=d1, start=list(b=-1, c =0, d=100, e=150))
Nonlinear regression model
       b        c        d        e
-1.1416   0.6987 102.8613 135.9373

Any suggestions would be appreciated!

John


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

d1.txt (302 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Concatenation

David Winsemius
In reply to this post by santana sarma

On May 21, 2010, at 12:21 AM, santana sarma wrote:

> Hi David,
>
> SORRY - I am trying to be more clearer this time.
>
> Let's say the dataframe has some rows and columns, with unique  
> rownames and column names. The rest of the data in the dataframe are  
> just numbers.

So have you tried any of the solutions offered so far?

c(apply(df[1:10,], 1, I))

c(df[ , 1:10]

This will not become any more clear unless you offer an R object. Your  
terminology has obviously been contaminated by excessive contact with  
spreadsheets. If you want R-answers you need to learn to define R-
objects and employ R-terminology.

--
David.

>
> I wish to concatenate those rows. That means : I wish to concatenate  
> first 10 rows' values in one row, then next 20 rows's values in the  
> next row .... and so on.
>
> Similarly, for columns : The first 10 column's values will be one  
> below the other ... and so on.
>
> Cheers,
>
>
> = = = = = = = = =  = =
>
>
> On Fri, May 21, 2010 at 3:53 PM, David Winsemius <[hidden email]
> > wrote:
>
> On May 20, 2010, at 11:05 PM, santana sarma wrote:
>
>  Hi,
>
> I have a dataframe with some 800 rows and 14 columns.
>
> Could you please advise how I can concatenate the rows - one after  
> another.
> Similarly for columns, one below the other.
>
> Not sure exactly what you are after:
>
> unlist might accomplish the second task.
>
> Whether c(apply(df, 1, I)) would be satisfactory for the first task  
> might depend on whether the columns in the dataframe were all of the  
> same type. Now that I think of it, both soolutions would force the  
> types to be that same.
>
> ?"c"
> ?I
> ?apply
>
> df[1:nrow(df), ]   ...  would essentially give you the first  
> request, but it would not be any different than just typing df.  
> So .... what do intend this process to accomplish?
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>

David Winsemius, MD
West Hartford, CT

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

Re: Concatenation

santana sarma
In reply to this post by Shi, Tao
Many thanks - the problem is solved.

Didn't realize that it was indeed simple. Thanks again.

Cheers,

        [[alternative HTML version deleted]]

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