Re: [R] transpose and split dataframe

2019-04-30 Thread Jim Lemon
Hi Matthew,
Is this what you are trying to do?

mmdf<-read.table(text="Regulatorhits
AT1G69490AT4G31950,AT5G24110,AT1G26380,AT1G05675
AT2G55980AT2G85403,AT4G89223",header=TRUE,
stringsAsFactors=FALSE)
# split the second column at the commas
hitsplit<-strsplit(mmdf$hits,",")
# define a function that will fill with NAs
NAfill<-function(x,n) return(x[1:n])
# get the maximum length of hits
maxlen<-max(unlist(lapply(hitsplit,length)))
# fill the list with NAs
hitsplit<-lapply(hitsplit,NAfill,maxlen)
# change the names of the list
names(hitsplit)<-mmdf$Regulator
# convert to a data frame
tmmdf<-as.data.frame(hitsplit)

Jim

On Wed, May 1, 2019 at 5:25 AM Matthew  wrote:
>
> I have a data frame that is a lot bigger but for simplicity sake we can
> say it looks like this:
>
> Regulatorhits
> AT1G69490AT4G31950,AT5G24110,AT1G26380,AT1G05675
> AT2G55980AT2G85403,AT4G89223
>
> In other words:
>
> data.frame : 2 obs. of 2 variables
> $Regulator: Factor w/ 2 levels
> $hits : Factor w/ 6 levels
>
>I want to transpose it so that Regulator is now the column headings
> and each of the AGI numbers now separated by commas is a row. So,
> AT1G69490 is now the header of the first column and AT4G31950 is row 1
> of column 1, AT5G24110 is row 2 of column 1, etc. AT2G55980 is header of
> column 2 and AT2G85403 is row 1 of column 2, etc.
>
>I have tried playing around with strsplit(TF2list[2:2]) and
> strsplit(as.character(TF2list[2:2]), but I am getting nowhere.
>
> Matthew
>
> __
> 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.


Re: [R] transpose and split dataframe

2019-04-30 Thread David L Carlson
I neglected to copy this to the list:

I think we need more information. Can you give us the structure of the data 
with str(YourDataFrame). Alternatively you could copy a small piece into your 
email message by copying and pasting the results of the following code:

dput(head(YourDataFrame))

The data frame you present could not be a data frame since you say "hits" is a 
factor with a variable number of elements. If each value of "hits" was a single 
character string, it would only have 2 factor levels not 6 and your efforts to 
parse the string would make more sense. Transposing to a data frame would only 
be possible if each column was padded with NAs to make them equal in length. 
Since your example tries use the name TF2list, it is possible that you do not 
have a data frame but a list and you have no factor levels, just character 
vectors.

If you are not familiar with R, it may be helpful to tell us what your overall 
goal is rather than an intermediate step. Very likely R can easily handle what 
you want by doing things a different way. 


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352



-Original Message-
From: R-help  On Behalf Of Matthew
Sent: Tuesday, April 30, 2019 2:25 PM
To: r-help (r-help@r-project.org) 
Subject: [R] transpose and split dataframe

I have a data frame that is a lot bigger but for simplicity sake we can 
say it looks like this:

Regulator    hits
AT1G69490    AT4G31950,AT5G24110,AT1G26380,AT1G05675
AT2G55980    AT2G85403,AT4G89223

    In other words:

data.frame : 2 obs. of 2 variables
$Regulator: Factor w/ 2 levels
$hits : Factor w/ 6 levels

   I want to transpose it so that Regulator is now the column headings 
and each of the AGI numbers now separated by commas is a row. So, 
AT1G69490 is now the header of the first column and AT4G31950 is row 1 
of column 1, AT5G24110 is row 2 of column 1, etc. AT2G55980 is header of 
column 2 and AT2G85403 is row 1 of column 2, etc.

   I have tried playing around with strsplit(TF2list[2:2]) and 
strsplit(as.character(TF2list[2:2]), but I am getting nowhere.

Matthew

__
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] transpose and split dataframe

2019-04-30 Thread Matthew
I have a data frame that is a lot bigger but for simplicity sake we can 
say it looks like this:


Regulator    hits
AT1G69490    AT4G31950,AT5G24110,AT1G26380,AT1G05675
AT2G55980    AT2G85403,AT4G89223

   In other words:

data.frame : 2 obs. of 2 variables
$Regulator: Factor w/ 2 levels
$hits : Factor w/ 6 levels

  I want to transpose it so that Regulator is now the column headings 
and each of the AGI numbers now separated by commas is a row. So, 
AT1G69490 is now the header of the first column and AT4G31950 is row 1 
of column 1, AT5G24110 is row 2 of column 1, etc. AT2G55980 is header of 
column 2 and AT2G85403 is row 1 of column 2, etc.


  I have tried playing around with strsplit(TF2list[2:2]) and 
strsplit(as.character(TF2list[2:2]), but I am getting nowhere.


Matthew

__
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] transpose rows and columns for large data

2016-11-30 Thread John Dougherty
On Tue, 29 Nov 2016 17:22:47 + (UTC)
Elham - via R-help  wrote:

> Is there another way (I prefer a way with Excel)?

Search on "friends don't let friends use excel for statistics."
Spreadsheets are an inherently perilous way to do statistics and Excel
specifically is notoriously poor. In fact the reason I originally began
using dedicated statistical packages (STATA first and now R) is that
spreadsheets (Excel in my case) can throw subtle errors that can create
problems. immediately, or even worse - later.  I had Excel return a
negative variance. Since variance is a squared value, unless you are
dealing with some very exotic numbers including imaginary values, a
negative variance is an absurd result.  Further investigation revealed
that other stat routines provided with Excel at the time were also
throwing errors that could look reasonable and thus be missed.  It was
also simply using erroneously constructed methods and providing
outright wrong results to things like Chi-square calculations.  

-- 

John

__
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] transpose rows and columns for large data

2016-11-29 Thread Marc Schwartz
Hi,

To provide a [very] small example of what Bert is referring to:

DF <- data.frame(Letters = letters[1:4], int = 1:4)

> str(DF)
'data.frame':   4 obs. of  2 variables:
 $ Letters: Factor w/ 4 levels "a","b","c","d": 1 2 3 4
 $ int: int  1 2 3 4

> DF
  Letters int
1   a   1
2   b   2
3   c   3
4   d   4


DFt <- t(DF)

> str(DFt)
 chr [1:2, 1:4] "a" "1" "b" "2" "c" "3" "d" "4"
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:2] "Letters" "int"
  ..$ : NULL

> DFt
[,1] [,2] [,3] [,4]
Letters "a"  "b"  "c"  "d" 
int "1"  "2"  "3"  "4" 


Note the change in the structure  and the data types of the data frame after 
the transposition...

A data frame, which is a special type of 'list', may contain multiple data 
types, one per column. It is designed, more or less, specifically to be able to 
handle multiple data types across the columns, as you might have in a database 
(character, numeric, date, etc.), but at the expense of some operations.

A matrix, which is in reality a vector with dimensions, can only contain a 
single data type and in this example, the numeric column is coerced to 
character. Note also that the "Letters" column in "DF" is changed from being a 
factor to character as well. So both columns are affected by the transposition.

Regards,

Marc Schwartz


> On Nov 29, 2016, at 1:33 PM, Bert Gunter  wrote:
> 
> No, no. It *is* for transposing. But it is *what* you are transposing
> -- a data frame -- that may lead to the problems. You will have to
> read what I referred you to and perhaps spend time with an R tutorial
> or two (there are many good ones on the web) if your R learning is not
> yet sufficient to understand what they say.
> 
> -- Bert
> 
> 
> 
> 
> Bert Gunter
> 
> "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 Tue, Nov 29, 2016 at 11:01 AM, Elham -  wrote:
>> excuse me I did not understand,you mean this function is not for
>> transposing? what function do you suggest?
>> 
>> 
>> On Tuesday, November 29, 2016 10:24 PM, Bert Gunter 
>> wrote:
>> 
>> 
>> It is probably worth mentioning that this (i.e. transposing a data
>> frame) can be a potentially disastrous thing to do in R, though the
>> explanation is probably more than you want to know at this point (see
>> ?t  and follow the 'as.matrix' link for details).  But if you start
>> getting weird results and error/warning messages when working with
>> your transposed data, at least you'll know why.
>> 
>> Cheers,
>> Bert
>> 
>> 
>> Bert Gunter
>> 
>> "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 Tue, Nov 29, 2016 at 10:37 AM, Elham - via R-help
>>  wrote:
>>> thank you all,it worked
>>> 
>>>   On Tuesday, November 29, 2016 9:49 PM, "Dalthorp, Daniel"
>>>  wrote:
>>> 
>>> 
>>> Try David's suggestion to spell the argument "stringsAsFactors"
>>> correctly. Then:
>>> 
>>> data <- read.table("your_file_location", sep ="\t", comment.char = "",
>>> stringsAsFactors = F, header = T)
>>> transpose_data <- t(data)
>>> 
>>> -Dan
>>> On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help 
>>> wrote:
>>> 
>>> yes you have right about excel.by R,what should I do for transposing row
>>> and column?
>>> 
>>>   On Tuesday, November 29, 2016 9:13 PM, David Winsemius
>>>  wrote:
>>> 
>>> 
>>> 
 On Nov 29, 2016, at 9:22 AM, Elham - via R-help 
 wrote:
 
 Hi,
 
 I am trying to transpose large datasets inexcel (44 columns and 57774
 rows) but it keeps giving me the message we can'tpaste because copy area 
 and
 paste area aren't the same size. Is there a way totranspose all the data at
 one time instead of piece by piece? One dataset has agreat amount of rows
 and columns.
 
 I tried this R function to transpose the datamatrix:
 
 data <- read.table("your_file_ location", sep ="\t", comment.char = "",
 stringAsFactors = F, header = T)
 
 
 
 transpose_data <- t(data)
 
 But I received tis error:
 
 unused argument (stringAsFactors = F)
 
>>> 
>>> You misspelled that argument's name. And do learn to use FALSE and TRUE.
>>> 
 
 Is there another way (I prefer a way with Excel)?
>>> 
>>> This is not a help list for Excel.
>>> 
>>> 
>>> --
>>> 
>>> 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.
>>> 
>>> 
>>> 
>>> --
>>> Dan Dalthorp, PhDUSGS Forest and Rangeland Ecosyste

Re: [R] transpose rows and columns for large data

2016-11-29 Thread Bert Gunter
No, no. It *is* for transposing. But it is *what* you are transposing
-- a data frame -- that may lead to the problems. You will have to
read what I referred you to and perhaps spend time with an R tutorial
or two (there are many good ones on the web) if your R learning is not
yet sufficient to understand what they say.

-- Bert




Bert Gunter

"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 Tue, Nov 29, 2016 at 11:01 AM, Elham -  wrote:
> excuse me I did not understand,you mean this function is not for
> transposing? what function do you suggest?
>
>
> On Tuesday, November 29, 2016 10:24 PM, Bert Gunter 
> wrote:
>
>
> It is probably worth mentioning that this (i.e. transposing a data
> frame) can be a potentially disastrous thing to do in R, though the
> explanation is probably more than you want to know at this point (see
> ?t  and follow the 'as.matrix' link for details).  But if you start
> getting weird results and error/warning messages when working with
> your transposed data, at least you'll know why.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "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 Tue, Nov 29, 2016 at 10:37 AM, Elham - via R-help
>  wrote:
>> thank you all,it worked
>>
>>On Tuesday, November 29, 2016 9:49 PM, "Dalthorp, Daniel"
>>  wrote:
>>
>>
>>  Try David's suggestion to spell the argument "stringsAsFactors"
>> correctly. Then:
>>
>> data <- read.table("your_file_location", sep ="\t", comment.char = "",
>> stringsAsFactors = F, header = T)
>> transpose_data <- t(data)
>>
>> -Dan
>> On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help 
>> wrote:
>>
>> yes you have right about excel.by R,what should I do for transposing row
>> and column?
>>
>>On Tuesday, November 29, 2016 9:13 PM, David Winsemius
>>  wrote:
>>
>>
>>
>>> On Nov 29, 2016, at 9:22 AM, Elham - via R-help 
>>> wrote:
>>>
>>> Hi,
>>>
>>> I am trying to transpose large datasets inexcel (44 columns and 57774
>>> rows) but it keeps giving me the message we can'tpaste because copy area and
>>> paste area aren't the same size. Is there a way totranspose all the data at
>>> one time instead of piece by piece? One dataset has agreat amount of rows
>>> and columns.
>>>
>>> I tried this R function to transpose the datamatrix:
>>>
>>> data <- read.table("your_file_ location", sep ="\t", comment.char = "",
>>> stringAsFactors = F, header = T)
>>>
>>>
>>>
>>> transpose_data <- t(data)
>>>
>>> But I received tis error:
>>>
>>> unused argument (stringAsFactors = F)
>>>
>>
>> You misspelled that argument's name. And do learn to use FALSE and TRUE.
>>
>>>
>>> Is there another way (I prefer a way with Excel)?
>>
>> This is not a help list for Excel.
>>
>>
>> --
>>
>> 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.
>>
>>
>>
>> --
>> Dan Dalthorp, PhDUSGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>
>> ddalth...@usgs.gov
>>
>>
>>
>>
>>[[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.


Re: [R] transpose rows and columns for large data

2016-11-29 Thread Bert Gunter
It is probably worth mentioning that this (i.e. transposing a data
frame) can be a potentially disastrous thing to do in R, though the
explanation is probably more than you want to know at this point (see
?t  and follow the 'as.matrix' link for details).  But if you start
getting weird results and error/warning messages when working with
your transposed data, at least you'll know why.

Cheers,
Bert


Bert Gunter

"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 Tue, Nov 29, 2016 at 10:37 AM, Elham - via R-help
 wrote:
> thank you all,it worked
>
> On Tuesday, November 29, 2016 9:49 PM, "Dalthorp, Daniel" 
>  wrote:
>
>
>  Try David's suggestion to spell the argument "stringsAsFactors" correctly. 
> Then:
>
> data <- read.table("your_file_location", sep ="\t", comment.char = "", 
> stringsAsFactors = F, header = T)
> transpose_data <- t(data)
>
> -Dan
> On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help  
> wrote:
>
> yes you have right about excel.by R,what should I do for transposing row and 
> column?
>
> On Tuesday, November 29, 2016 9:13 PM, David Winsemius 
>  wrote:
>
>
>
>> On Nov 29, 2016, at 9:22 AM, Elham - via R-help  wrote:
>>
>> Hi,
>>
>> I am trying to transpose large datasets inexcel (44 columns and 57774 rows) 
>> but it keeps giving me the message we can'tpaste because copy area and paste 
>> area aren't the same size. Is there a way totranspose all the data at one 
>> time instead of piece by piece? One dataset has agreat amount of rows and 
>> columns.
>>
>> I tried this R function to transpose the datamatrix:
>>
>> data <- read.table("your_file_ location", sep ="\t", comment.char = "", 
>> stringAsFactors = F, header = T)
>>
>>
>>
>> transpose_data <- t(data)
>>
>> But I received tis error:
>>
>> unused argument (stringAsFactors = F)
>>
>
> You misspelled that argument's name. And do learn to use FALSE and TRUE.
>
>>
>> Is there another way (I prefer a way with Excel)?
>
> This is not a help list for Excel.
>
>
> --
>
> 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.
>
>
>
> --
> Dan Dalthorp, PhDUSGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
>
>
>
> [[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.


Re: [R] transpose rows and columns for large data

2016-11-29 Thread Elham - via R-help
thank you all,it worked 

On Tuesday, November 29, 2016 9:49 PM, "Dalthorp, Daniel" 
 wrote:
 

 Try David's suggestion to spell the argument "stringsAsFactors" correctly. 
Then:

data <- read.table("your_file_location", sep ="\t", comment.char = "", 
stringsAsFactors = F, header = T)
transpose_data <- t(data)

-Dan
On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help  
wrote:

yes you have right about excel.by R,what should I do for transposing row and 
column?

    On Tuesday, November 29, 2016 9:13 PM, David Winsemius 
 wrote:



> On Nov 29, 2016, at 9:22 AM, Elham - via R-help  wrote:
>
> Hi,
>
> I am trying to transpose large datasets inexcel (44 columns and 57774 rows) 
> but it keeps giving me the message we can'tpaste because copy area and paste 
> area aren't the same size. Is there a way totranspose all the data at one 
> time instead of piece by piece? One dataset has agreat amount of rows and 
> columns.
>
> I tried this R function to transpose the datamatrix:
>
> data <- read.table("your_file_ location", sep ="\t", comment.char = "", 
> stringAsFactors = F, header = T)
>
>
> 
> transpose_data <- t(data)
>
> But I received tis error:
>
> unused argument (stringAsFactors = F)
>

You misspelled that argument's name. And do learn to use FALSE and TRUE.

> 
> Is there another way (I prefer a way with Excel)?

This is not a help list for Excel.


--

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.



-- 
Dan Dalthorp, PhDUSGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way 
Corvallis, OR 97331 
ph: 541-750-0953
ddalth...@usgs.gov



   
[[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] transpose rows and columns for large data

2016-11-29 Thread Dalthorp, Daniel
Try David's suggestion to spell the argument "stringsAsFactors" correctly.
Then:

data <- read.table("your_file_location", sep ="\t", comment.char = "",
stringsAsFactors = F, header = T)
transpose_data <- t(data)

-Dan

On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help 
wrote:

> yes you have right about excel.by R,what should I do for transposing row
> and column?
>
> On Tuesday, November 29, 2016 9:13 PM, David Winsemius <
> dwinsem...@comcast.net> wrote:
>
>
>
> > On Nov 29, 2016, at 9:22 AM, Elham - via R-help 
> wrote:
> >
> > Hi,
> >
> > I am trying to transpose large datasets inexcel (44 columns and 57774
> rows) but it keeps giving me the message we can'tpaste because copy area
> and paste area aren't the same size. Is there a way totranspose all the
> data at one time instead of piece by piece? One dataset has agreat amount
> of rows and columns.
> >
> > I tried this R function to transpose the datamatrix:
> >
> > data <- read.table("your_file_location", sep ="\t", comment.char = "",
> stringAsFactors = F, header = T)
> >
> >
> >
> > transpose_data <- t(data)
> >
> > But I received tis error:
> >
> > unused argument (stringAsFactors = F)
> >
>
> You misspelled that argument's name. And do learn to use FALSE and TRUE.
>
> >
> > Is there another way (I prefer a way with Excel)?
>
> This is not a help list for Excel.
>
>
> --
>
> 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.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] transpose rows and columns for large data

2016-11-29 Thread Bert Gunter
It's 'stringsAsFactors' = FALSE (without my added quotes) with an 's'
at the end of 'strings' .

-- Bert
Bert Gunter

"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 Tue, Nov 29, 2016 at 9:22 AM, Elham - via R-help
 wrote:
> Hi,
>
> I am trying to transpose large datasets inexcel (44 columns and 57774 rows) 
> but it keeps giving me the message we can'tpaste because copy area and paste 
> area aren't the same size. Is there a way totranspose all the data at one 
> time instead of piece by piece? One dataset has agreat amount of rows and 
> columns.
>
> I tried this R function to transpose the datamatrix:
>
> data <- read.table("your_file_location", sep ="\t", comment.char = "", 
> stringAsFactors = F, header = T)
>
>
>
> transpose_data <- t(data)
>
> But I received tis error:
>
> unused argument (stringAsFactors = F)
>
>
>
>
>
> Is there another way (I prefer a way with Excel)?
>
>
> [[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.


Re: [R] transpose rows and columns for large data

2016-11-29 Thread Elham - via R-help
yes you have right about excel.by R,what should I do for transposing row and 
column? 

On Tuesday, November 29, 2016 9:13 PM, David Winsemius 
 wrote:
 

 
> On Nov 29, 2016, at 9:22 AM, Elham - via R-help  wrote:
> 
> Hi,
> 
> I am trying to transpose large datasets inexcel (44 columns and 57774 rows) 
> but it keeps giving me the message we can'tpaste because copy area and paste 
> area aren't the same size. Is there a way totranspose all the data at one 
> time instead of piece by piece? One dataset has agreat amount of rows and 
> columns. 
> 
> I tried this R function to transpose the datamatrix:
> 
> data <- read.table("your_file_location", sep ="\t", comment.char = "", 
> stringAsFactors = F, header = T)
> 
> 
>  
> transpose_data <- t(data)
> 
> But I received tis error:
> 
> unused argument (stringAsFactors = F)
> 

You misspelled that argument's name. And do learn to use FALSE and TRUE.

>  
> Is there another way (I prefer a way with Excel)?

This is not a help list for Excel.


-- 

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] transpose rows and columns for large data

2016-11-29 Thread David Winsemius

> On Nov 29, 2016, at 9:22 AM, Elham - via R-help  wrote:
> 
> Hi,
> 
> I am trying to transpose large datasets inexcel (44 columns and 57774 rows) 
> but it keeps giving me the message we can'tpaste because copy area and paste 
> area aren't the same size. Is there a way totranspose all the data at one 
> time instead of piece by piece? One dataset has agreat amount of rows and 
> columns. 
> 
> I tried this R function to transpose the datamatrix:
> 
> data <- read.table("your_file_location", sep ="\t", comment.char = "", 
> stringAsFactors = F, header = T)
> 
> 
>  
> transpose_data <- t(data)
> 
> But I received tis error:
> 
> unused argument (stringAsFactors = F)
> 

You misspelled that argument's name. And do learn to use FALSE and TRUE.

>  
> Is there another way (I prefer a way with Excel)?

This is not a help list for Excel.


-- 

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.


[R] transpose rows and columns for large data

2016-11-29 Thread Elham - via R-help
Hi,

I am trying to transpose large datasets inexcel (44 columns and 57774 rows) but 
it keeps giving me the message we can'tpaste because copy area and paste area 
aren't the same size. Is there a way totranspose all the data at one time 
instead of piece by piece? One dataset has agreat amount of rows and columns. 

I tried this R function to transpose the datamatrix:

data <- read.table("your_file_location", sep ="\t", comment.char = "", 
stringAsFactors = F, header = T)


 
transpose_data <- t(data)

But I received tis error:

unused argument (stringAsFactors = F)


 

 
Is there another way (I prefer a way with Excel)?


[[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] transpose a data frame according to a specific variable

2015-02-10 Thread jeff6868
Both ways are doing well the job. Nice!
Thanks again!



--
View this message in context: 
http://r.789695.n4.nabble.com/transpose-a-data-frame-according-to-a-specific-variable-tp4702971p4703007.html
Sent from the R help mailing list archive at Nabble.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.


Re: [R] transpose a data frame according to a specific variable

2015-02-09 Thread Erich Neuwirth

library(tidyr)
spread(DF,Year,Day)




> On 09 Feb 2015, at 16:47, jeff6868  wrote:
> 
> finalDF <-
> data.frame(id=c("A","B","C"),"2000"=c(NA,NA,164),"2001"=c(120,NA,99),
> "2002"=c(90,18,48),"2003"=c(54,217,NA),"2004"=c(NA,68,NA))



signature.asc
Description: Message signed with OpenPGP using GPGMail
__
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] transpose a data frame according to a specific variable

2015-02-09 Thread Dennis Murphy
One way is to use the reshape2 package:

library(reshape2)
dcast(DF, id ~ Year, value.var = "Day")


Dennis

On Mon, Feb 9, 2015 at 7:47 AM, jeff6868
 wrote:
> Dear R-users,
>
> I would like to transpose a large data.frame according to a specific column.
> Here's a reproductible example, it will be more understandable.
>
> At the moment, my data.frame looks like this example:
>
> DF <- data.frame(id=c("A","A","A","B","B","B","C","C","C"),
> Year=c(2001,2002,2003,2002,2003,2004,2000,2001,2002),
> Day=c(120,90,54,18,217,68,164,99,48))
>
> I would like it being transformed to this (fake example again, still just
> for being understandable):
>
> finalDF <-
> data.frame(id=c("A","B","C"),"2000"=c(NA,NA,164),"2001"=c(120,NA,99),
> "2002"=c(90,18,48),"2003"=c(54,217,NA),"2004"=c(NA,68,NA))
>
> Any ideas for doing this easily? I haven't found any good answer on the web.
>
> Thanks for the help!
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/transpose-a-data-frame-according-to-a-specific-variable-tp4702971.html
> Sent from the R help mailing list archive at Nabble.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.

__
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] transpose a data frame according to a specific variable

2015-02-09 Thread jeff6868
Dear R-users,

I would like to transpose a large data.frame according to a specific column.
Here's a reproductible example, it will be more understandable.

At the moment, my data.frame looks like this example:

DF <- data.frame(id=c("A","A","A","B","B","B","C","C","C"),
Year=c(2001,2002,2003,2002,2003,2004,2000,2001,2002),
Day=c(120,90,54,18,217,68,164,99,48))

I would like it being transformed to this (fake example again, still just
for being understandable):

finalDF <-
data.frame(id=c("A","B","C"),"2000"=c(NA,NA,164),"2001"=c(120,NA,99),
"2002"=c(90,18,48),"2003"=c(54,217,NA),"2004"=c(NA,68,NA))

Any ideas for doing this easily? I haven't found any good answer on the web.

Thanks for the help!




--
View this message in context: 
http://r.789695.n4.nabble.com/transpose-a-data-frame-according-to-a-specific-variable-tp4702971.html
Sent from the R help mailing list archive at Nabble.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.


Re: [R] Transpose of the rows

2013-06-26 Thread Blaser Nello
reshape(dta, idvar="id", timevar="name", direction="wide")


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Nico Met
Sent: Mittwoch, 26. Juni 2013 13:38
To: R help
Subject: [R] Transpose of the rows

Dear R users,

I am using a big data matrix and need to transpose rows (formatting of
input matrix). I would like write a general code for this example.

for example: my input file is "dta"

 dput(dta)
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L), .Label = c("TN00016-003A", "TN00016-014A",
"TN00031-014A"), class = "factor"), name = structure(c(1L, 2L, 3L, 4L,
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("AreaCycl",
"AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"), class = "factor"),
value = structure(c(3L, 7L, 8L, 14L, 12L, 1L, 2L, 9L, 5L,
13L, 11L, 10L, 4L, 6L), .Label = c("-0,584379415", "-0,842892819",
"-1,399894415", "-1200,824457", "-13,59414667", "-25,86897333",
"-3,277150907", "-3281,076515", "-7939,444248", "0,174160882",
"0,800196212", "1,825", "12,2", "8,43449"), class = "factor")),
...Names = c("id", "name", "value"), class = "data.frame", row.names =
c(NA, -14L
))

And output should look like this:

dput(dta1)
structure(list(id = structure(1:3, .Label = c("TN00016-003A",
"TN00016-014A", "TN00031-014A"), class = "factor"), AreaCycl =
structure(c( 2L, 1L, 3L), .Label = c("-0,584379415", "-1,399894415",
"0,800196212"
), class = "factor"), AreaEmer = structure(c(2L, 1L, 3L), .Label = c(
"-0,842892819", "-3,277150907", "0,174160882"), class = "factor"),
AreaMax = structure(c( 2L, 3L, 1L), .Label = c("-1200,824457",
"-3281,076515", "-7939,444248"
), class = "factor"), HeightMax = structure(c(3L, 1L, 2L), .Label = c(
"-13,59414667", "-25,86897333", "8,43449"), class = "factor"),
nrfilledseed = structure( c(1L, 2L, NA), .Label = c("1,825", "12,2"),
class = "factor")), .Names = c("id", "AreaCycl", "AreaEmer", "AreaMax",
"HeightMax", "nrfilledseed"
), class = "data.frame", row.names = c(NA, -3L))

Thanks for your help.

Nico

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose of the rows

2013-06-26 Thread arun
 dta[,3]<-as.numeric(as.character(gsub(",",".",dta[,3])))
library(reshape2)

  dcast(dta,id~name,value.var="value")
#    id   AreaCycl   AreaEmer   AreaMax  HeightMax nrfilledseed
#1 TN00016-003A -1.3998944 -3.2771509 -3281.077   8.434493    1.825
#2 TN00016-014A -0.5843794 -0.8428928 -7939.444 -13.594147   12.200
#3 TN00031-014A  0.8001962  0.1741609 -1200.824 -25.868973   NA

A.K.


- Original Message -
From: Nico Met 
To: R help 
Cc: 
Sent: Wednesday, June 26, 2013 7:37 AM
Subject: [R] Transpose of the rows

Dear R users,

I am using a big data matrix and need to transpose rows (formatting of
input matrix). I would like write a general code for this example.

for example: my input file is "dta"

dput(dta)
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L), .Label = c("TN00016-003A", "TN00016-014A",
"TN00031-014A"), class = "factor"), name = structure(c(1L, 2L,
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("AreaCycl",
"AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"), class = "factor"),
    value = structure(c(3L, 7L, 8L, 14L, 12L, 1L, 2L, 9L, 5L,
    13L, 11L, 10L, 4L, 6L), .Label = c("-0,584379415", "-0,842892819",
    "-1,399894415", "-1200,824457", "-13,59414667", "-25,86897333",
    "-3,277150907", "-3281,076515", "-7939,444248", "0,174160882",
    "0,800196212", "1,825", "12,2", "8,43449"), class = "factor")),
.Names = c("id",
"name", "value"), class = "data.frame", row.names = c(NA, -14L
))

And output should look like this:

dput(dta1)
structure(list(id = structure(1:3, .Label = c("TN00016-003A",
"TN00016-014A", "TN00031-014A"), class = "factor"), AreaCycl = structure(c(
2L,
1L, 3L), .Label = c("-0,584379415", "-1,399894415", "0,800196212"
), class = "factor"), AreaEmer = structure(c(2L, 1L, 3L), .Label = c(
"-0,842892819",
"-3,277150907", "0,174160882"), class = "factor"), AreaMax = structure(c(
2L,
3L, 1L), .Label = c("-1200,824457", "-3281,076515", "-7939,444248"
), class = "factor"), HeightMax = structure(c(3L, 1L, 2L), .Label = c(
"-13,59414667",
"-25,86897333", "8,43449"), class = "factor"), nrfilledseed = structure(
c(1L,
2L, NA), .Label = c("1,825", "12,2"), class = "factor")), .Names = c("id",
"AreaCycl", "AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"
), class = "data.frame", row.names = c(NA, -3L))

Thanks for your help.

Nico

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transpose of the rows

2013-06-26 Thread Nico Met
Dear R users,

I am using a big data matrix and need to transpose rows (formatting of
input matrix). I would like write a general code for this example.

for example: my input file is "dta"

 dput(dta)
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L), .Label = c("TN00016-003A", "TN00016-014A",
"TN00031-014A"), class = "factor"), name = structure(c(1L, 2L,
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("AreaCycl",
"AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"), class = "factor"),
value = structure(c(3L, 7L, 8L, 14L, 12L, 1L, 2L, 9L, 5L,
13L, 11L, 10L, 4L, 6L), .Label = c("-0,584379415", "-0,842892819",
"-1,399894415", "-1200,824457", "-13,59414667", "-25,86897333",
"-3,277150907", "-3281,076515", "-7939,444248", "0,174160882",
"0,800196212", "1,825", "12,2", "8,43449"), class = "factor")),
.Names = c("id",
"name", "value"), class = "data.frame", row.names = c(NA, -14L
))

And output should look like this:

dput(dta1)
structure(list(id = structure(1:3, .Label = c("TN00016-003A",
"TN00016-014A", "TN00031-014A"), class = "factor"), AreaCycl = structure(c(
2L,
1L, 3L), .Label = c("-0,584379415", "-1,399894415", "0,800196212"
), class = "factor"), AreaEmer = structure(c(2L, 1L, 3L), .Label = c(
"-0,842892819",
"-3,277150907", "0,174160882"), class = "factor"), AreaMax = structure(c(
2L,
3L, 1L), .Label = c("-1200,824457", "-3281,076515", "-7939,444248"
), class = "factor"), HeightMax = structure(c(3L, 1L, 2L), .Label = c(
"-13,59414667",
"-25,86897333", "8,43449"), class = "factor"), nrfilledseed = structure(
c(1L,
2L, NA), .Label = c("1,825", "12,2"), class = "factor")), .Names = c("id",
"AreaCycl", "AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"
), class = "data.frame", row.names = c(NA, -3L))

Thanks for your help.

Nico

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread arun
Hi,
You can try:
mat1<- do.call(rbind,x)
lapply(seq_len(ncol(mat1)),function(i) mat1[,i])
#[[1]]
#[1] 12.10  3.44

#[[2]]
#[1] 0.1 3.0

#[[3]]
#[1] 12.0 33.1

#[[4]]
#[1]  1.1 23.0


A.K.

- Original Message -
From: ishi soichi 
To: PIKAL Petr 
Cc: r-help 
Sent: Friday, March 8, 2013 5:06 AM
Subject: Re: [R] transpose lists

Thanks. The result should be a list of lists like...

> x
[[1]]
[1] 12.10  3.44

[[2]]
[1] 0.1 3.0

[[3]]
[1] 12.0 33.1

[[4]]
[1]  1.1 23.0

lapply(x, t) doesn't do the job, I think.

ishida


2013/3/8 PIKAL Petr 

> Hi
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of ishi soichi
> > Sent: Friday, March 08, 2013 10:50 AM
> > To: r-help
> > Subject: [R] transpose lists
> >
> > Can you think of a function that transposes a list like
>
> What shall be the result of transposed list?
>
> Something like
>
> lapply(x, t)
>
> Regards
> Petr
>
> >
> > > x
> > [[1]]
> > [1] 12.1  0.1 12.0  1.1
> >
> > [[2]]
> > [1]  3.44  3.00 33.10 23.00
> >
> > ?
> >
> > ishida
> >
> >       [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread Jorge I Velez
One option would be

x <- list(c(12.1, 0.1, 12, 1.1), c(3.44, 3, 33.1, 23))
do.call(c, apply(do.call(rbind, x), 2, list))

HTH,
Jorge.-



On Fri, Mar 8, 2013 at 9:06 PM, ishi soichi  wrote:

> Thanks. The result should be a list of lists like...
>
> > x
> [[1]]
> [1] 12.10  3.44
>
> [[2]]
> [1] 0.1 3.0
>
> [[3]]
> [1] 12.0 33.1
>
> [[4]]
> [1]  1.1 23.0
>
> lapply(x, t) doesn't do the job, I think.
>
> ishida
>
>
> 2013/3/8 PIKAL Petr 
>
> > Hi
> >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > > project.org] On Behalf Of ishi soichi
> > > Sent: Friday, March 08, 2013 10:50 AM
> > > To: r-help
> > > Subject: [R] transpose lists
> > >
> > > Can you think of a function that transposes a list like
> >
> > What shall be the result of transposed list?
> >
> > Something like
> >
> > lapply(x, t)
> >
> > Regards
> > Petr
> >
> > >
> > > > x
> > > [[1]]
> > > [1] 12.1  0.1 12.0  1.1
> > >
> > > [[2]]
> > > [1]  3.44  3.00 33.10 23.00
> > >
> > > ?
> > >
> > > ishida
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/posting-
> > > guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread ishi soichi
Thanks! Certainly they do help!

ishida


2013/3/8 D. Rizopoulos 

> two possibilities are:
>
> lis <- list(c(12.1,0.1,12.0,1.1), c(3.44,3.00,33.10,23.00))
>
> # 1st
> m <- do.call(rbind, lis)
> split(m, col(m))
>
> # 2nd
> lapply(seq_along(lis[[1]]),
>  function (i) sapply(lis, "[", i))
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
> On 3/8/2013 11:06 AM, ishi soichi wrote:
> > Thanks. The result should be a list of lists like...
> >
> >> x
> > [[1]]
> > [1] 12.10  3.44
> >
> > [[2]]
> > [1] 0.1 3.0
> >
> > [[3]]
> > [1] 12.0 33.1
> >
> > [[4]]
> > [1]  1.1 23.0
> >
> > lapply(x, t) doesn't do the job, I think.
> >
> > ishida
> >
> >
> > 2013/3/8 PIKAL Petr 
> >
> >> Hi
> >>
> >>> -Original Message-
> >>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> >>> project.org] On Behalf Of ishi soichi
> >>> Sent: Friday, March 08, 2013 10:50 AM
> >>> To: r-help
> >>> Subject: [R] transpose lists
> >>>
> >>> Can you think of a function that transposes a list like
> >>
> >> What shall be the result of transposed list?
> >>
> >> Something like
> >>
> >> lapply(x, t)
> >>
> >> Regards
> >> Petr
> >>
> >>>
> >>>> x
> >>> [[1]]
> >>> [1] 12.1  0.1 12.0  1.1
> >>>
> >>> [[2]]
> >>> [1]  3.44  3.00 33.10 23.00
> >>>
> >>> ?
> >>>
> >>> ishida
> >>>
> >>>[[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide http://www.R-project.org/posting-
> >>> guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
>
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread D. Rizopoulos
two possibilities are:

lis <- list(c(12.1,0.1,12.0,1.1), c(3.44,3.00,33.10,23.00))

# 1st
m <- do.call(rbind, lis)
split(m, col(m))

# 2nd
lapply(seq_along(lis[[1]]),
 function (i) sapply(lis, "[", i))


I hope it helps.

Best,
Dimitris


On 3/8/2013 11:06 AM, ishi soichi wrote:
> Thanks. The result should be a list of lists like...
>
>> x
> [[1]]
> [1] 12.10  3.44
>
> [[2]]
> [1] 0.1 3.0
>
> [[3]]
> [1] 12.0 33.1
>
> [[4]]
> [1]  1.1 23.0
>
> lapply(x, t) doesn't do the job, I think.
>
> ishida
>
>
> 2013/3/8 PIKAL Petr 
>
>> Hi
>>
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>>> project.org] On Behalf Of ishi soichi
>>> Sent: Friday, March 08, 2013 10:50 AM
>>> To: r-help
>>> Subject: [R] transpose lists
>>>
>>> Can you think of a function that transposes a list like
>>
>> What shall be the result of transposed list?
>>
>> Something like
>>
>> lapply(x, t)
>>
>> Regards
>> Petr
>>
>>>
>>>> x
>>> [[1]]
>>> [1] 12.1  0.1 12.0  1.1
>>>
>>> [[2]]
>>> [1]  3.44  3.00 33.10 23.00
>>>
>>> ?
>>>
>>> ishida
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-
>>> guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread ishi soichi
Thanks. The result should be a list of lists like...

> x
[[1]]
[1] 12.10  3.44

[[2]]
[1] 0.1 3.0

[[3]]
[1] 12.0 33.1

[[4]]
[1]  1.1 23.0

lapply(x, t) doesn't do the job, I think.

ishida


2013/3/8 PIKAL Petr 

> Hi
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of ishi soichi
> > Sent: Friday, March 08, 2013 10:50 AM
> > To: r-help
> > Subject: [R] transpose lists
> >
> > Can you think of a function that transposes a list like
>
> What shall be the result of transposed list?
>
> Something like
>
> lapply(x, t)
>
> Regards
> Petr
>
> >
> > > x
> > [[1]]
> > [1] 12.1  0.1 12.0  1.1
> >
> > [[2]]
> > [1]  3.44  3.00 33.10 23.00
> >
> > ?
> >
> > ishida
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose lists

2013-03-08 Thread PIKAL Petr
Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of ishi soichi
> Sent: Friday, March 08, 2013 10:50 AM
> To: r-help
> Subject: [R] transpose lists
> 
> Can you think of a function that transposes a list like

What shall be the result of transposed list?

Something like

lapply(x, t)

Regards
Petr

> 
> > x
> [[1]]
> [1] 12.1  0.1 12.0  1.1
> 
> [[2]]
> [1]  3.44  3.00 33.10 23.00
> 
> ?
> 
> ishida
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] transpose lists

2013-03-08 Thread ishi soichi
Can you think of a function that transposes a list like

> x
[[1]]
[1] 12.1  0.1 12.0  1.1

[[2]]
[1]  3.44  3.00 33.10 23.00

?

ishida

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose a big data file and write to a new file

2013-03-07 Thread Claudia Beleites
Hi Yao He,

this doesn't sound like R to me. I'd go for perl (or awk).

See e.g. here:
http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash

HTH

Claudia

Am Wed, 6 Mar 2013 22:37:14 +0800
schrieb Yao He :

> Dear all:
> 
> I have a big data file of 6 columns and 6 rows like that:
> 
> AA AC AA AA ...AT
> CC CC CT CT...TC
> ..
> .
> 
> I want to transpose it and the output is a new like that
> AA CC 
> AC CC
> AA CT.
> AA CT.
> 
> 
> AT TC.
> 
> The keypoint is  I can't read it into R by read.table() because the
> data is too large,so I try that:
> c<-file("silygenotype.txt","r")
> geno_t<-list()
> repeat{
>   line<-readLines(c,n=1)
>   if (length(line)==0)break  #end of file
>   line<-unlist(strsplit(line,"\t"))
> geno_t<-cbind(geno_t,line)
> }
>  write.table(geno_t,"xxx.txt")
> 
> It works but it is too slow ,how to optimize it???
> 
> Thank you
> 
> Yao He
> —
> Master candidate in 2rd year
> Department of Animal genetics & breeding
> Room 436,College of Animial Science&Technology,
> China Agriculture University,Beijing,100193
> E-mail: yao.h.1...@gmail.com
> ——
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.



-- 
Claudia Beleites
Spectroscopy/Imaging
Institute of Photonic Technology 
Albert-Einstein-Str. 9
07745 Jena
Germany

email: claudia.belei...@ipht-jena.de
phone: +49 3641 206-133
fax:   +49 2641 206-399

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Rui Barradas
quot;8.494", 
> "y"), class = "factor"), D2 = structure(c(7L, 3L, 3L, 3L, 
> 4L, 3L, 5L, 4L, 3L, 5L, 3L, 3L, 3L, 3L, 1L, 4L, 3L, 5L, 4L, 
> 5L, 2L, 4L, 3L, 4L, 3L, 6L, 5L, 2L), .Label = c("12.794", 
> "12.795", "12.796", "12.797", "12.798", "12.802", "x"), class =
> "factor"), 
> D2.1 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L), .Label = c("6.273", "y"), class = "factor"), 
> D3 = structure(c(5L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 1L, 2L, 3L, 3L, 2L, 3L, 
> 2L, 3L, 3L), .Label = c("12.775", "12.776", "12.777", "12.778", 
> "x"), class = "factor"), D3.1 = structure(c(2L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("4.034", 
> "y"), class = "factor"), D4 = structure(c(8L, 2L, 3L, 2L, 
> 4L, 1L, 3L, 4L, 3L, 4L, 4L, 3L, 3L, 5L, 4L, 5L, 5L, 5L, 5L, 
> 4L, 6L, 5L, 7L, 5L, 5L, 4L, 5L, 6L), .Label = c("12.499", 
> "12.501", "12.502", "12.503", "12.504", "12.505", "12.506", 
> "x"), class = "factor"), D4.1 = structure(c(8L, 5L, 1L, 6L, 
> 6L, 2L, 6L, 6L, 7L, 5L, 6L, 5L, 2L, 6L, 4L, 7L, 2L, 2L, 4L, 
> 1L, 5L, 4L, 5L, 5L, 4L, 1L, 2L, 3L), .Label = c("2.142", 
> "2.143", "2.144", "2.145", "2.146", "2.147", "2.148", "y"
> ), class = "factor"), E2 = structure(c(8L, 1L, 1L, 2L, 3L, 
> 4L, 2L, 4L, 4L, 3L, 3L, 5L, 4L, 4L, 5L, 3L, 4L, 3L, 3L, 3L, 
> 6L, 4L, 3L, 4L, 6L, 6L, 7L, 4L), .Label = c("17.01", "17.013", 
> "17.014", "17.015", "17.016", "17.017", "17.018", "x"), class =
> "factor"), 
> E2.1 = structure(c(6L, 5L, 1L, 1L, 4L, 2L, 1L, 4L, 3L, 4L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L), .Label = c("6.813", "6.814", "6.815", "6.816", 
> "6.819", "y"), class = "factor"), E3 = structure(c(6L, 5L, 
> 5L, 3L, 2L, 3L, 4L, 2L, 1L, 4L, 3L, 2L, 5L, 3L, 1L, 2L, 3L, 
> 2L, 2L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 1L, 2L), .Label = c("17.061", 
> "17.062", "17.063", "17.064", "17.065", "x"), class = "factor"), 
> E3.1 = structure(c(9L, 1L, 2L, 3L, 3L, 6L, 2L, 3L, 6L, 7L, 
> 4L, 7L, 4L, 4L, 4L, 6L, 8L, 5L, 6L, 4L, 5L, 8L, 7L, 7L, 7L, 
> 4L, 6L, 7L), .Label = c("4.265", "4.266", "4.267", "4.268", 
> "4.269", "4.27", "4.271", "4.272", "y"), class = "factor"), 
> E4 = structure(c(7L, 3L, 4L, 4L, 4L, 5L, 6L, 5L, 4L, 2L, 
> 4L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 2L, 5L, 3L, 3L, 3L, 3L, 3L, 
> 4L, 4L, 6L), .Label = c("17.443", "17.444", "17.445", "17.446", 
> "17.447", "17.448", "x"), class = "factor"), E4.1 = structure(c(7L, 
> 6L, 5L, 3L, 3L, 4L, 2L, 1L, 3L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 
> 1L, 2L, 2L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L), .Label = c("2.357", 
> "2.358", "2.359", "2.36", "2.362", "2.364", "y"), class = "factor"), 
> F1 = structure(c(13L, 9L, 6L, 9L, 12L, 11L, 7L, 3L, 10L, 
> 5L, 5L, 6L, 7L, 9L, 3L, 9L, 5L, 8L, 1L, 3L, 3L, 8L, 2L, 6L, 
> 4L, 2L, 3L, 3L), .Label = c("19.828", "19.829", "19.83", 
> "19.831", "19.832", "19.833", "19.834", "19.835", "19.836", 
> "19.837", "19.838", "19.839", "x"), class = "factor"), F1.1 =
> structure(c(9L, 
> 1L, 5L, 1L, 1L, 3L, 3L, 4L, 2L, 3L, 1L, 3L, 4L, 3L, 4L, 7L, 
> 6L, 3L, 5L, 6L, 6L, 6L, 8L, 7L, 8L, 6L, 7L, 6L), .Label = c("8.775", 
> "8.776", "8.777", "8.778", "8.779", "8.78", "8.781", "8.782", 
> "y"), class = "factor"), F3 = structure(c(6L, 5L, 5L, 2L, 
> 3L, 5L, 5L, 3L, 1L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 4L, 3L, 5L, 
> 4L, 3L, 4L, 4L, 4L, 3L, 2L, 3L, 5L), .Label = c("19.521", 
> "19.522", "19.523", "19.524", "19.525", "x"), class = "factor"), 
> F3.1 = structure(c(10L, 6L, 8L, 6L, 5L, 9L, 7L, 5L, 5L, 7L, 
> 6L, 5L, 6L, 4L, 4L, 3L, 4L, 3L, 4L, 4L, 2L, 3L, 2L, 3L, 1L, 
> 4L, 5L, 3L), .Label = c("4.227", "4.228", "4.229", "4.23", 
> "4.231", "4.232", "4.233", "4.234", "4.236", "y"), class = "factor"), 
> F2 = structure(c(7L, 3L, 5L, 6L, 4L, 4L, 4L, 4L, 3L, 3L, 
> 2L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 1L, 3L, 3L, 3L, 3L, 1L, 2L, 
> 3L, 6L, 5L), .Label = c("19.491", "19.492", "19.493", "19.494", 
> "19.495", "19.496", "x"), class = "factor"), F2.1 = structure(c(5L, 
> 4L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 4L, 3L, 4L, 4L, 4L, 4L, 
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("6.423", 
> "6.425", "6.426", "6.427", "y"), class = "factor"), F4 =
> structure(c(6L, 
> 4L, 2L, 2L, 3L, 3L, 1L, 2L, 3L, 2L, 5L, 2L, 1L, 3L, 1L, 2L, 
> 3L, 2L, 2L, 2L, 1L, 3L, 1L, 4L, 1L, 3L, 2L, 3L), .Label = c("19.573", 
> "19.574", "19.575", "19.576", "19.577", "x"), class = "factor"), 
> F4.1 = structure(c(6L, 5L, 3L, 1L, 4L, 2L, 3L, 1L, 1L, 2L, 
> 3L, 2L, 2L, 2L, 1L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, 2L, 2L, 3L, 
> 3L, 2L, 1L), .Label = c("2.514", "2.515", "2.516", "2.517", 
> "2.521", "y"), class = "factor"), G1 = structure(c(9L, 5L, 
> 5L, 6L, 5L, 5L, 4L, 2L, 5L, 4L, 6L, 7L, 3L, 1L, 3L, 4L, 6L, 
> 5L, 6L, 6L, 4L, 3L, 2L, 3L, 5L, 3L, 8L, 5L), .Label = c("21.994", 
> "21.999", "22", "22.001", "22.002", "22.003", "22.004", "22.006", 
> "x"), class = "factor"), G1.1 = structure(c(10L, 9L, 7L, 
> 5L, 8L, 7L, 6L, 8L, 5L, 7L, 4L, 5L, 7L, 6L, 4L, 7L, 8L, 3L, 
> 2L, 8L, 5L, 6L, 5L, 4L, 6L, 3L, 5L, 1L), .Label = c("8.713", 
> "8.715", "8.717", "8.718", "8.719", "8.72", "8.721", "8.722", 
> "8.724", "y"), class = "factor"), G2 = structure(c(9L, 6L, 
> 6L, 4L, 4L, 4L, 5L, 6L, 4L, 3L, 1L, 4L, 5L, 4L, 3L, 4L, 4L, 
> 4L, 5L, 5L, 3L, 4L, 5L, 5L, 2L, 7L, 8L, 6L), .Label = c("21.936", 
> "21.937", "21.938", "21.939", "21.94", "21.941", "21.942", 
> "21.943", "x"), class = "factor"), G2.1 = structure(c(5L, 
> 4L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("6.388", 
> "6.389", "6.391", "6.396", "y"), class = "factor")), .Names = c("A2", 
> "A2.1", "A3", "A3.1", "A4", "A4.1", "B1", "B1.1", "A1", "A1.1", 
> "B2", "B2.1", "B3", "B3.1", "B4", "B4.1", "C1", "C1.1", "C2", 
> "C2.1", "C3", "C3.1", "C4", "C4.1", "D1", "D1.1", "D2", "D2.1", 
> "D3", "D3.1", "D4", "D4.1", "E2", "E2.1", "E3", "E3.1", "E4", 
> "E4.1", "F1", "F1.1", "F3", "F3.1", "F2", "F2.1", "F4", "F4.1", 
> "G1", "G1.1", "G2", "G2.1"), class = "data.frame", row.names = c(NA, 
> -28L))
>>
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4610151.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread marc212
1L, 6L, 
6L, 2L, 6L, 6L, 7L, 5L, 6L, 5L, 2L, 6L, 4L, 7L, 2L, 2L, 4L, 
1L, 5L, 4L, 5L, 5L, 4L, 1L, 2L, 3L), .Label = c("2.142", 
"2.143", "2.144", "2.145", "2.146", "2.147", "2.148", "y"
), class = "factor"), E2 = structure(c(8L, 1L, 1L, 2L, 3L, 
4L, 2L, 4L, 4L, 3L, 3L, 5L, 4L, 4L, 5L, 3L, 4L, 3L, 3L, 3L, 
6L, 4L, 3L, 4L, 6L, 6L, 7L, 4L), .Label = c("17.01", "17.013", 
"17.014", "17.015", "17.016", "17.017", "17.018", "x"), class =
"factor"), 
E2.1 = structure(c(6L, 5L, 1L, 1L, 4L, 2L, 1L, 4L, 3L, 4L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("6.813", "6.814", "6.815", "6.816", 
"6.819", "y"), class = "factor"), E3 = structure(c(6L, 5L, 
5L, 3L, 2L, 3L, 4L, 2L, 1L, 4L, 3L, 2L, 5L, 3L, 1L, 2L, 3L, 
2L, 2L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 1L, 2L), .Label = c("17.061", 
"17.062", "17.063", "17.064", "17.065", "x"), class = "factor"), 
E3.1 = structure(c(9L, 1L, 2L, 3L, 3L, 6L, 2L, 3L, 6L, 7L, 
4L, 7L, 4L, 4L, 4L, 6L, 8L, 5L, 6L, 4L, 5L, 8L, 7L, 7L, 7L, 
4L, 6L, 7L), .Label = c("4.265", "4.266", "4.267", "4.268", 
"4.269", "4.27", "4.271", "4.272", "y"), class = "factor"), 
E4 = structure(c(7L, 3L, 4L, 4L, 4L, 5L, 6L, 5L, 4L, 2L, 
4L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 2L, 5L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 6L), .Label = c("17.443", "17.444", "17.445", "17.446", 
"17.447", "17.448", "x"), class = "factor"), E4.1 = structure(c(7L, 
6L, 5L, 3L, 3L, 4L, 2L, 1L, 3L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 
1L, 2L, 2L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L), .Label = c("2.357", 
"2.358", "2.359", "2.36", "2.362", "2.364", "y"), class = "factor"), 
F1 = structure(c(13L, 9L, 6L, 9L, 12L, 11L, 7L, 3L, 10L, 
5L, 5L, 6L, 7L, 9L, 3L, 9L, 5L, 8L, 1L, 3L, 3L, 8L, 2L, 6L, 
4L, 2L, 3L, 3L), .Label = c("19.828", "19.829", "19.83", 
"19.831", "19.832", "19.833", "19.834", "19.835", "19.836", 
"19.837", "19.838", "19.839", "x"), class = "factor"), F1.1 =
structure(c(9L, 
1L, 5L, 1L, 1L, 3L, 3L, 4L, 2L, 3L, 1L, 3L, 4L, 3L, 4L, 7L, 
6L, 3L, 5L, 6L, 6L, 6L, 8L, 7L, 8L, 6L, 7L, 6L), .Label = c("8.775", 
"8.776", "8.777", "8.778", "8.779", "8.78", "8.781", "8.782", 
"y"), class = "factor"), F3 = structure(c(6L, 5L, 5L, 2L, 
3L, 5L, 5L, 3L, 1L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 4L, 3L, 5L, 
4L, 3L, 4L, 4L, 4L, 3L, 2L, 3L, 5L), .Label = c("19.521", 
"19.522", "19.523", "19.524", "19.525", "x"), class = "factor"), 
F3.1 = structure(c(10L, 6L, 8L, 6L, 5L, 9L, 7L, 5L, 5L, 7L, 
6L, 5L, 6L, 4L, 4L, 3L, 4L, 3L, 4L, 4L, 2L, 3L, 2L, 3L, 1L, 
4L, 5L, 3L), .Label = c("4.227", "4.228", "4.229", "4.23", 
"4.231", "4.232", "4.233", "4.234", "4.236", "y"), class = "factor"), 
F2 = structure(c(7L, 3L, 5L, 6L, 4L, 4L, 4L, 4L, 3L, 3L, 
2L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 1L, 3L, 3L, 3L, 3L, 1L, 2L, 
3L, 6L, 5L), .Label = c("19.491", "19.492", "19.493", "19.494", 
"19.495", "19.496", "x"), class = "factor"), F2.1 = structure(c(5L, 
4L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 4L, 3L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("6.423", 
"6.425", "6.426", "6.427", "y"), class = "factor"), F4 = structure(c(6L, 
4L, 2L, 2L, 3L, 3L, 1L, 2L, 3L, 2L, 5L, 2L, 1L, 3L, 1L, 2L, 
3L, 2L, 2L, 2L, 1L, 3L, 1L, 4L, 1L, 3L, 2L, 3L), .Label = c("19.573", 
"19.574", "19.575", "19.576", "19.577", "x"), class = "factor"), 
F4.1 = structure(c(6L, 5L, 3L, 1L, 4L, 2L, 3L, 1L, 1L, 2L, 
3L, 2L, 2L, 2L, 1L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, 2L, 2L, 3L, 
3L, 2L, 1L), .Label = c("2.514", "2.515", "2.516", "2.517", 
"2.521", "y"), class = "factor"), G1 = structure(c(9L, 5L, 
5L, 6L, 5L, 5L, 4L, 2L, 5L, 4L, 6L, 7L, 3L, 1L, 3L, 4L, 6L, 
5L, 6L, 6L, 4L, 3L, 2L, 3L, 5L, 3L, 8L, 5L), .Label = c("21.994", 
"21.999", "22", "22.001", "22.002", "22.003", "22.004", "22.006", 
"x"), class = "factor"), G1.1 = structure(c(10L, 9L, 7L, 
5L, 8L, 7L, 6L, 8L, 5L, 7L, 4L, 5L, 7L, 6L, 4L, 7L, 8L, 3L, 
2L, 8L, 5L, 6L, 5L, 4L, 6L, 3L, 5L, 1L), .Label = c("8.713", 
"8.715", "8.717", "8.718", "8.719", "8.72", "8.721", "8.722", 
"8.724", "y"), class = "factor"), G2 = structure(c(9L, 6L, 
6L, 4L, 4L, 4L, 5L, 6L, 4L, 3L, 1L, 4L, 5L, 4L, 3L, 4L, 4L, 
4L, 5L, 5L, 3L, 4L, 5L, 5L, 2L, 7L, 8L, 6L), .Label = c("21.936", 
"21.937", "21.938", "21.939", "21.94", "21.941", "21.942", 
"21.943", "x"), class = "factor"), G2.1 = structure(c(5L, 
4L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("6.388", 
"6.389", "6.391", "6.396", "y"), class = "factor")), .Names = c("A2", 
"A2.1", "A3", "A3.1", "A4", "A4.1", "B1", "B1.1", "A1", "A1.1", 
"B2", "B2.1", "B3", "B3.1", "B4", "B4.1", "C1", "C1.1", "C2", 
"C2.1", "C3", "C3.1", "C4", "C4.1", "D1", "D1.1", "D2", "D2.1", 
"D3", "D3.1", "D4", "D4.1", "E2", "E2.1", "E3", "E3.1", "E4", 
"E4.1", "F1", "F1.1", "F3", "F3.1", "F2", "F2.1", "F4", "F4.1", 
"G1", "G1.1", "G2", "G2.1"), class = "data.frame", row.names = c(NA, 
-28L))
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4610059.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Rui Barradas
Hello, again.

marc212 wrote
> 
> I have a pretty good computer with a lot of RAM and it just wont run this
> code.  My R crashes...
> 
> Running this on a sample does not work either.
> 
> Any advice? Thank you for all the help!
> 
> Marc
> 
What I'm saying is to use dput on a data sample.
For instance, with 'orig' created as above,

dput(orig)
structure(c(5, 3, 5, 6, 4, 2, 6, 4, 6, 7, 3, 4, 7, 9, 7, 9, 9, 
4), .Dim = c(3L, 6L), .Dimnames = list(c("0", "1", "2"), c("x", 
"y", "x", "y", "x", "y")))

If you post an example like this, we'll know better what to do.
It's just a matter of copy&paste to an R session.

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4610046.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Rui Barradas
Hello,


marc212 wrote
> 
> I am not opposed to for loops just do not know how to implement them.
> 
> 
> I am sorry for all the questions I am trying to learn.  The posted code
> does not work for me in my set I am getting a :
> Error in `dimnames<-.data.frame`(`*tmp*`, value = list(c("A1", "A1.1",  : 
>   invalid 'dimnames' given for data frame
> 
> Any help is much appreciated.
> 
> Thank you.
> 

Try commenting out the line dimnames <- list(... etc ...)
You could also use dput() to post an example of your data.
(Small example.)

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609748.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread marc212
I am not opposed to for loops just do not know how to implement them.


I am sorry for all the questions I am trying to learn.  The posted code does
not work for me in my set I am getting a :
Error in `dimnames<-.data.frame`(`*tmp*`, value = list(c("A1", "A1.1",  : 
  invalid 'dimnames' given for data frame

Any help is much appreciated.

Thank you.




--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609658.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Rui Barradas
Hello,


marc212 wrote
> 
> I have the following:
> Time   A1   A1   B1   B1   C1   C2
>   x y x  y   x y
>  0 5 6  6  7  7  9
>   1 3 4  4  3  9  9  
>   2 5 2  6  4 7   4
> 
> I want to change it to the following:
> 0   1 2
> xy xy xy 
> A1  56 3   4  52
> B1  67 4   3  6   4
> etc for a much larger set
> 
> I am sure there are ways to accomplish through a lot of for loops but I
> feel there is most likely a function to use.
> 
> Thank you.
> 

Using Petr's Orig data.frame above, maybe this is what you want.

cnames <- unique(colnames(Orig))
nc <- ncol(Orig)/length(cnames)

res <- lapply(seq.int(nrow(Orig)), function(i){
x <- Orig[i, ]
dim(x) <- c(length(cnames), nc)
dimnames(x) <- list(cnames, LETTERS[seq_len(nc)])
t(x)
})
names(res) <- rownames(Orig)
res
do.call(cbind, res)

And it avoids loops.

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609488.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Petr Savicky
On Fri, May 04, 2012 at 11:11:47AM -0700, marc212 wrote:
> I have something like 28 rows and 6000 columns.  How would I configure this
> with for loops.

The transformation may be splitted into simpler pieces using a for
loop over the 28 rows. Try the following.

  orig <- rbind(
  "0"=c(5, 6, 6, 7, 7, 9),
  "1"=c(3, 4, 4, 3, 9, 9),
  "2"=c(5, 2, 6, 4, 7, 4))
  colnames(orig) <- rep(c("x", "y"), times=3)

  out <- matrix(nrow=ncol(orig)/2, ncol=2*nrow(orig))
  for (i in seq.int(length=nrow(orig))) {
  out[, 2*(i-1) + 1:2] <- matrix(orig[i, ], nrow=nrow(out), ncol=2, 
byrow=TRUE)
  }

  out

   [,1] [,2] [,3] [,4] [,5] [,6]
  [1,]563452
  [2,]674364
  [3,]799974

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread marc212
I have something like 28 rows and 6000 columns.  How would I configure this
with for loops.

Thank you.


Marc

--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609309.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Breaking up a Row in R (transpose)

2012-05-04 Thread Petr Savicky
On Thu, May 03, 2012 at 07:36:45PM -0700, marc212 wrote:
> I have the following:
> Time   A1   A1   B1   B1   C1   C2
>   x y x  y   x y
>  0 5 6  6  7  7  9
>   1 3 4  4  3  9  9  
>   2 5 2  6  4 7   4
> 
> I want to change it to the following:
> 0   1 2
> xy xy xy 
> A1  56 3   4  52
> B1  67 4   3  6   4
> etc for a much larger set

Hi.

Try the following.

  # the example input
  Orig <- rbind(
  "0"=c(5, 6, 6, 7, 7, 9),
  "1"=c(3, 4, 4, 3, 9, 9),
  "2"=c(5, 2, 6, 4, 7, 4))
  colnames(Orig) <- rep(c("x", "y"), times=3)

  # transformation
  Arr <- array(Orig, dim=c(nrow(Orig), 2, ncol(Orig)/2))
  Arr

  , , 1# this is the required row 1 in the output
  
   [,1] [,2]
  [1,]56
  [2,]34
  [3,]52
  
  , , 2# this is the required row 2 in the output
  
   [,1] [,2]
  [1,]67
  [2,]43
  [3,]64
  
  , , 3
  
   [,1] [,2]
  [1,]79
  [2,]99
  [3,]74

  Arr1 <- aperm(Arr, perm=c(2, 1, 3))
  d <- dim(Arr1)
  t(array(Arr1, dim=c(d[1]*d[2], d[3])))

   [,1] [,2] [,3] [,4] [,5] [,6]
  [1,]563452
  [2,]674364
  [3,]799974

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Breaking up a Row in R (transpose)

2012-05-04 Thread marc212
I have the following:
Time   A1   A1   B1   B1   C1   C2
  x y x  y   x y
 0 5 6  6  7  7  9
  1 3 4  4  3  9  9  
  2 5 2  6  4 7   4

I want to change it to the following:
0   1 2
xy xy xy 
A1  56 3   4  52
B1  67 4   3  6   4
etc for a much larger set

I am sure there are ways to accomplish through a lot of for loops but I feel
there is most likely a function to use.

Thank you. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose ?

2011-05-25 Thread Scott Chamberlain
See ?t

__Scott Chamberlain
Rice University, EEB Dept.

On Wednesday, May 25, 2011 at 9:07 AM, Mohamed Lajnef wrote: 
> Dear All,
> Suppose this data.frame
> D
> 
> V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22
> C C C C T T G G A A C C G G C C
> G G T T A A A A T A T T C C G G
> C C C C T T G G A A C C G G C C
> 
> 
> I would translate D as follow ( just for the first line)
> C (V7)
>  C (V9)
>  T G A C G C
> C (V8)
>  C (V10)
>  T G A C G C
> 
> 
> Any help would be appreciated
> 
> Regards
> M
> 
> -- 
> 
> Mohamed Lajnef,IE INSERM U955 eq 15#
> Pôle de Psychiatrie # 
> Hôpital CHENEVIER #
> 40, rue Mesly #
> 94010 CRETEIL Cedex FRANCE #
> mohamed.laj...@inserm.fr #
> tel : 01 49 81 32 79 #
> Sec : 01 49 81 32 90 #
> fax : 01 49 81 30 99 #
> 
> 
> 
> 
>  [[alternative HTML version deleted]]
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] transpose ?

2011-05-25 Thread Mohamed Lajnef
Dear All,
Suppose this data.frame
D

V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22
C  C  C   C   T   T   G   G   A   A   C   C   G   G   C   C
G  G  T   T   A   A   A   A   T   A   T   T   C   C   G   G
C  C  C   C   T   T   G   G   A   A   C   C   G   G   C   C


I would translate D as follow ( just for the first line)
C (V7)
C (V9)
T   G   A   C   G   C
C (V8)
C (V10)
T   G   A   C   G   C


Any help would be appreciated

Regards
M

-- 

Mohamed Lajnef,IE INSERM U955 eq 15#
Pôle de Psychiatrie#
Hôpital CHENEVIER  #
40, rue Mesly  #
94010 CRETEIL Cedex FRANCE #
mohamed.laj...@inserm.fr   #
tel : 01 49 81 32 79   #
Sec : 01 49 81 32 90   #
fax : 01 49 81 30 99   #




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-23 Thread Patrick Hausmann

Ups, I mean library(reshape) not plyr, sorry

# Example datasets
# Input
propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
  R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
  R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))

library(reshape)
xpropsum <- melt(propsum, id.var="coverClass", variable_name = "Image")
tpropsum <- reshape(xpropsum, timevar="coverClass", idvar="Image", 
direction="wide")

colnames(tpropsum) <- sub("value.", "", colnames(tpropsum))
tpropsum

HTH,
Patrick

Am 23.04.2010 12:16, schrieb Patrick Hausmann:

Hi David,

you could use a mix of "plyr" and reshape:

# Example datasets
# Input
propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))

library(plyr)
xpropsum <- melt(propsum, id.var="coverClass", variable_name = "Image")
tpropsum <- reshape(xpropsum, timevar="coverClass", idvar="Image",
direction="wide")
colnames(tpropsum) <- sub("value.", "", colnames(tpropsum))
tpropsum

Cheers
Patrick


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-23 Thread Henrique Dallazuanna
Try this:

xtabs(values ~ ind + cover, cbind(cover = propsum$coverClass,
stack(propsum)))

On Fri, Apr 23, 2010 at 1:43 AM,  wrote:

> Greetings all,
>
> I am having difficulty transposing, reshaping, flipping (not sure which) a
> data frame which is read from a DBF file.  I have tried using t(), reshape()
> and other approaches without success. Can anyone please suggest an way
> (elegant or not) of flipping this data around ?
>
> The initial data is like propsum (defined below), and I want it to look
> like tpropsum once reformed.
> > propsum
>  coverClass R209120812 R209122212
> 1  C NA   0.05
> 2  G   0.49   0.35
> 3  L   0.38   0.41
> 4  O   0.04   0.09
> 5  S   0.09   0.10
>
> > tpropsum
>   ImageCGLO  L.1
> 1 R209120812   NA 0.49 0.38 0.04 0.09
> 2 R209122212 0.05 0.35 0.41 0.09 0.10
>
> # Example datasets
> # Input
> propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
>  R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
>  R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))
>
> # Desired output
> tpropsum <- data.frame(Image=c("R209120812", "R209122212"),
>  C=c(NA, 0.05),
>  G=c(0.49, 0.35),
>  L=c(0.38, 0.41),
>  O=c(0.04, 0.09),
>  L=c(0.09, 0.10))
>
> Thanks,
> David
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-23 Thread Carl Witthoft
While the OP turned out to want to transpose his data, for those who are 
reading and would like some (ugly) code to flip a tensor about an 
arbitrary axis, here goes:

*_*  Carl


#my own cheap matrix flipflopper
flip<-function(x,flipdim=1) {
#axis is index, so 1 is rows, 2 is cols (for matrix)
#sanity check
	if (flipdim > length(dim(x))) stop("Dimension selected exceeds dim of 
input")

a <-"x["
b<-paste("dim(x)[",flipdim,"]:1",collapse="")
d <-"]"
# want lead and follow to be a single vector
#now the trick: get the right number of commas
lead<-paste(rep(',',(flipdim-1)),collapse="")
follow <-paste(rep(',',(length(dim(x))-flipdim)),collapse="")
thestr<-paste(a,lead,b,follow,d,collapse="")
flipped<-eval(parse(text=thestr))
return(invisible(flipped))
}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-23 Thread Patrick Hausmann

Hi David,

you could use a mix of "plyr" and reshape:

# Example datasets
# Input
propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
  R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
  R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))

library(plyr)
xpropsum <- melt(propsum, id.var="coverClass", variable_name = "Image")
tpropsum <- reshape(xpropsum, timevar="coverClass", idvar="Image", 
direction="wide")

colnames(tpropsum) <- sub("value.", "", colnames(tpropsum))
tpropsum

Cheers
Patrick

Am 23.04.2010 06:43, schrieb david.gobb...@csiro.au:

Greetings all,

I am having difficulty transposing, reshaping, flipping (not sure which) a data 
frame which is read from a DBF file.  I have tried using t(), reshape() and 
other approaches without success. Can anyone please suggest an way (elegant or 
not) of flipping this data around ?

The initial data is like propsum (defined below), and I want it to look like 
tpropsum once reformed.

propsum

   coverClass R209120812 R209122212
1  C NA   0.05
2  G   0.49   0.35
3  L   0.38   0.41
4  O   0.04   0.09
5  S   0.09   0.10


tpropsum

ImageCGLO  L.1
1 R209120812   NA 0.49 0.38 0.04 0.09
2 R209122212 0.05 0.35 0.41 0.09 0.10

# Example datasets
# Input
propsum<- data.frame(coverClass=c("C", "G", "L", "O", "S"),
   R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
   R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))

# Desired output
tpropsum<- data.frame(Image=c("R209120812", "R209122212"),
   C=c(NA, 0.05),
   G=c(0.49, 0.35),
   L=c(0.38, 0.41),
   O=c(0.04, 0.09),
   L=c(0.09, 0.10))

Thanks,
David

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-22 Thread David.Gobbett
Fabulous!  I managed to get close with t(), but had obviously missed the step 
of setting the rownames first.

Thanks for your help!
David

-Original Message-
From: Ista Zahn [mailto:istaz...@gmail.com] 
Sent: Friday, 23 April 2010 2:29 PM
To: Gobbett, David (CSE, Waite Campus)
Cc: r-help@r-project.org
Subject: Re: [R] transpose? reshape? flipping? challenge with data frame

Hi David,
There are many ways, including

rownames(propsum) <- propsum$coverClass
propsum$coverClass <- NULL
t(propsum)

Best,
Ista

On Fri, Apr 23, 2010 at 5:43 AM,   wrote:
> Greetings all,
>
> I am having difficulty transposing, reshaping, flipping (not sure which) a 
> data frame which is read from a DBF file.  I have tried using t(), reshape() 
> and other approaches without success. Can anyone please suggest an way 
> (elegant or not) of flipping this data around ?
>
> The initial data is like propsum (defined below), and I want it to look like 
> tpropsum once reformed.
>> propsum
>  coverClass R209120812 R209122212
> 1          C         NA       0.05
> 2          G       0.49       0.35
> 3          L       0.38       0.41
> 4          O       0.04       0.09
> 5          S       0.09       0.10
>
>> tpropsum
>       Image    C    G    L    O  L.1
> 1 R209120812   NA 0.49 0.38 0.04 0.09
> 2 R209122212 0.05 0.35 0.41 0.09 0.10
>
> # Example datasets
> # Input
> propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
>                      R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
>                      R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))
>
> # Desired output
> tpropsum <- data.frame(Image=c("R209120812", "R209122212"),
>                      C=c(NA, 0.05),
>                      G=c(0.49, 0.35),
>                      L=c(0.38, 0.41),
>                      O=c(0.04, 0.09),
>                      L=c(0.09, 0.10))
>
> Thanks,
> David
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose? reshape? flipping? challenge with data frame

2010-04-22 Thread Ista Zahn
Hi David,
There are many ways, including

rownames(propsum) <- propsum$coverClass
propsum$coverClass <- NULL
t(propsum)

Best,
Ista

On Fri, Apr 23, 2010 at 5:43 AM,   wrote:
> Greetings all,
>
> I am having difficulty transposing, reshaping, flipping (not sure which) a 
> data frame which is read from a DBF file.  I have tried using t(), reshape() 
> and other approaches without success. Can anyone please suggest an way 
> (elegant or not) of flipping this data around ?
>
> The initial data is like propsum (defined below), and I want it to look like 
> tpropsum once reformed.
>> propsum
>  coverClass R209120812 R209122212
> 1          C         NA       0.05
> 2          G       0.49       0.35
> 3          L       0.38       0.41
> 4          O       0.04       0.09
> 5          S       0.09       0.10
>
>> tpropsum
>       Image    C    G    L    O  L.1
> 1 R209120812   NA 0.49 0.38 0.04 0.09
> 2 R209122212 0.05 0.35 0.41 0.09 0.10
>
> # Example datasets
> # Input
> propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
>                      R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
>                      R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))
>
> # Desired output
> tpropsum <- data.frame(Image=c("R209120812", "R209122212"),
>                      C=c(NA, 0.05),
>                      G=c(0.49, 0.35),
>                      L=c(0.38, 0.41),
>                      O=c(0.04, 0.09),
>                      L=c(0.09, 0.10))
>
> Thanks,
> David
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] transpose? reshape? flipping? challenge with data frame

2010-04-22 Thread David.Gobbett
Greetings all,

I am having difficulty transposing, reshaping, flipping (not sure which) a data 
frame which is read from a DBF file.  I have tried using t(), reshape() and 
other approaches without success. Can anyone please suggest an way (elegant or 
not) of flipping this data around ?

The initial data is like propsum (defined below), and I want it to look like 
tpropsum once reformed.
> propsum
  coverClass R209120812 R209122212
1  C NA   0.05
2  G   0.49   0.35
3  L   0.38   0.41
4  O   0.04   0.09
5  S   0.09   0.10

> tpropsum
   ImageCGLO  L.1
1 R209120812   NA 0.49 0.38 0.04 0.09
2 R209122212 0.05 0.35 0.41 0.09 0.10

# Example datasets
# Input
propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"),
  R209120812=c(NA, 0.49, 0.38, 0.04, 0.09),
  R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10))

# Desired output
tpropsum <- data.frame(Image=c("R209120812", "R209122212"),
  C=c(NA, 0.05),
  G=c(0.49, 0.35),
  L=c(0.38, 0.41),
  O=c(0.04, 0.09),
  L=c(0.09, 0.10))

Thanks,
David

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose but different

2010-04-13 Thread Gabor Grothendieck
Try this.  First we use outer to form a matrix such that i,j-th entry
is TRUE if i, j are in the same group and unequal and FALSE otherwise.
 We apply which on the rows of that matrix to get the groups that are
associated with the row group.  We then cbind the components together
using ts class to prevent recycling and cbind that to a.  Finally we
remove the ugly rownames.  Note that if a has N rows then an NxN
matrix will be created

gps <- apply(outer(a$group, a$group, "==") & !diag(nrow(a)), 1, which)
out <- cbind(a, t(do.call(cbind, lapply(gps, ts
rownames(out) <- NULL

On Tue, Apr 13, 2010 at 8:04 AM, Duijvesteijn, Naomi
 wrote:
>
>   Hi all,
>
>
>
>   I  want  to  make  extra  columns in my datafile where the id of every
>   groupmember is mentioned in separate columns. To explain it better see the
>   example:
>
>
>
>   id<-c(1,2,3,4,5,6,7,8,9,10,11,12)
>
>   group<-c(1,1,1,1,2,2,3,3,3,3,3,3)
>
>   a<-as.data.frame(cbind(id,group))
>
>   a
>
>      id group
>
>   1   1     1
>
>   2   2     1
>
>   3   3     1
>
>   4   4     1
>
>   5   5     2
>
>   6   6     2
>
>   7   7     3
>
>   8   8     3
>
>   9   9     3
>
>   10 10     3
>
>   11 11     3
>
>   12 12     3
>
>
>
>   Result should be (gm = groupmember)
>
>
>   id  group   gm1         gm2       gm3      gm4           gm5       gm6
>     gm7            etc.
>
>   1     1          2             3           4          NA            NA
>   NA            NA
>
>   2     1          1             3           4          NA            NA
>   NA            NA
>
>   3     1          1             2           4          NA            NA
>   NA            NA
>
>   4     1          1             2           3          NA            NA
>   NA            NA
>
>   5     2          6             NA          NA        NA             NA
>   NA            NA
>
>   6     2          5             NA          NA        NA             NA
>   NA            NA
>
>   7     3          8            9           10          11            12
>     NA             NA
>
>   8        3            7               9              10             11
>   12          NA             NA
>
>   9        3            7               8              10             11
>   12          NA             NA
>
>   10       3            7               8              9              11
>   12          NA             NA
>
>   11       3            7               8              9              10
>   12          NA             NA
>
>   12       3            7               8              9              10
>   11          NA             NA
>
>
>
>   What I have been trying so far is reshape, but this doesn’t put the id’s of
>   the groupmembers of different groups under the same columnname. It makes new
>   columnnames per group.
>
>
>   Couls somebody help me out with this? I really appreciate it
>
>
>   Regards,
>
>   Naomi Duijvesteijn
>
>
>
>
>   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
>   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
>   Aan dit bericht kunnen geen rechten of plichten worden ontleend.
>
>   
>   
>
>   Disclaimer: The information contained in this message may be confidential
>   and is intended to be exclusively for the addressee. Should you receive this
>   message unintentionally, you are expected not to use the contents herein, to
>   notify the sender immediately and to destroy the message. No rights can be
>   derived from this message.
>
>
>   P Please consider the environment before printing this email
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose but different

2010-04-13 Thread jim holtman
try this:

> x <- read.table(textConnection(" id group
+   1   1 1
+   2   2 1
+   3   3 1
+   4   4 1
+   5   5 2
+   6   6 2
+   7   7 3
+   8   8 3
+   9   9 3
+   10 10 3
+   11 11 3
+   12 12 3"), header=TRUE)
> # split by group and process
> result <- lapply(split(x, x$group), function(i){
+ # create combinations
+ com <- combn(i$id, length(i$id) - 1L)
+ t(apply(com, 2, function(.col){
+ c(setdiff(i$id, .col), i$group[1L], .col)
+ }))
+ })
> # determine maximum number of column
> col.max <- max(sapply(result, ncol))
> # now create output with proper number of columns
> output <- do.call(rbind, lapply(result, function(.grp){
+ while (ncol(.grp) < col.max) .grp <- cbind(.grp, NA)
+ .grp
+ }))
>
> # add column names
> colnames(output) <- c('id', 'group', paste('gm', seq(col.max - 2),
sep=''))
> output
  id group gm1 gm2 gm3 gm4 gm5
 [1,]  4 1   1   2   3  NA  NA
 [2,]  3 1   1   2   4  NA  NA
 [3,]  2 1   1   3   4  NA  NA
 [4,]  1 1   2   3   4  NA  NA
 [5,]  6 2   5  NA  NA  NA  NA
 [6,]  5 2   6  NA  NA  NA  NA
 [7,] 12 3   7   8   9  10  11
 [8,] 11 3   7   8   9  10  12
 [9,] 10 3   7   8   9  11  12
[10,]  9 3   7   8  10  11  12
[11,]  8 3   7   9  10  11  12
[12,]  7 3   8   9  10  11  12
>


On Tue, Apr 13, 2010 at 8:04 AM, Duijvesteijn, Naomi <
naomi.duijveste...@ipg.nl> wrote:

>
>   Hi all,
>
>
>
>   I  want  to  make  extra  columns in my datafile where the id of every
>   groupmember is mentioned in separate columns. To explain it better see
> the
>   example:
>
>
>
>   id<-c(1,2,3,4,5,6,7,8,9,10,11,12)
>
>   group<-c(1,1,1,1,2,2,3,3,3,3,3,3)
>
>   a<-as.data.frame(cbind(id,group))
>
>   a
>
>  id group
>
>   1   1 1
>
>   2   2 1
>
>   3   3 1
>
>   4   4 1
>
>   5   5 2
>
>   6   6 2
>
>   7   7 3
>
>   8   8 3
>
>   9   9 3
>
>   10 10 3
>
>   11 11 3
>
>   12 12 3
>
>
>
>   Result should be (gm = groupmember)
>
>
>   id  group   gm1 gm2   gm3  gm4   gm5   gm6
> gm7etc.
>
>   1 1  2 3   4  NANA
>   NANA
>
>   2 1  1 3   4  NANA
>   NANA
>
>   3 1  1 2   4  NANA
>   NANA
>
>   4 1  1 2   3  NANA
>   NANA
>
>   5 2  6 NA  NANA NA
>   NANA
>
>   6 2  5 NA  NANA NA
>   NANA
>
>   7 3  89   10  1112
> NA NA
>
>   837   9  10 11
>   12  NA NA
>
>   937   8  10 11
>   12  NA NA
>
>   10   37   8  9  11
>   12  NA NA
>
>   11   37   8  9  10
>   12  NA NA
>
>   12   37   8  9  10
>   11  NA NA
>
>
>
>   What I have been trying so far is reshape, but this doesn’t put the id’s
> of
>   the groupmembers of different groups under the same columnname. It makes
> new
>   columnnames per group.
>
>
>   Couls somebody help me out with this? I really appreciate it
>
>
>   Regards,
>
>   Naomi Duijvesteijn
>
>
>
>
>   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet
> te
>   gebruiken, de afzender direct te informeren en het bericht te
> vernietigen.
>   Aan dit bericht kunnen geen rechten of plichten worden ontleend.
>
>
> 
>   
>
>   Disclaimer: The information contained in this message may be confidential
>   and is intended to be exclusively for the addressee. Should you receive
> this
>   message unintentionally, you are expected not to use the contents herein,
> to
>   notify the sender immediately and to destroy the message. No rights can
> be
>   derived from this message.
>
>
>   P Please consider the environment before printing this email
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Jim Holtman
Cincin

[R] transpose but different

2010-04-13 Thread Duijvesteijn, Naomi

   Hi all,



   I  want  to  make  extra  columns in my datafile where the id of every
   groupmember is mentioned in separate columns. To explain it better see the
   example:



   id<-c(1,2,3,4,5,6,7,8,9,10,11,12)

   group<-c(1,1,1,1,2,2,3,3,3,3,3,3)

   a<-as.data.frame(cbind(id,group))

   a

  id group

   1   1 1

   2   2 1

   3   3 1

   4   4 1

   5   5 2

   6   6 2

   7   7 3

   8   8 3

   9   9 3

   10 10 3

   11 11 3

   12 12 3



   Result should be (gm = groupmember)


   id  group   gm1 gm2   gm3  gm4   gm5   gm6
 gm7etc.

   1 1  2 3   4  NANA
   NANA

   2 1  1 3   4  NANA
   NANA

   3 1  1 2   4  NANA
   NANA

   4 1  1 2   3  NANA
   NANA

   5 2  6 NA  NANA NA
   NANA

   6 2  5 NA  NANA NA
   NANA

   7 3  89   10  1112
 NA NA

   837   9  10 11
   12  NA NA

   937   8  10 11
   12  NA NA

   10   37   8  9  11
   12  NA NA

   11   37   8  9  10
   12  NA NA

   12   37   8  9  10
   11  NA NA



   What I have been trying so far is reshape, but this doesn’t put the id’s 
of
   the groupmembers of different groups under the same columnname. It makes new
   columnnames per group.


   Couls somebody help me out with this? I really appreciate it


   Regards,

   Naomi Duijvesteijn

   
   
   
   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
   gebruiken, de afzender direct te informeren en het bericht te vernietigen.
   Aan dit bericht kunnen geen rechten of plichten worden ontleend.

   
   

   Disclaimer: The information contained in this message may be confidential
   and is intended to be exclusively for the addressee. Should you receive this
   message unintentionally, you are expected not to use the contents herein, to
   notify the sender immediately and to destroy the message. No rights can be
   derived from this message.

   
   P Please consider the environment before printing this email
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose a dataset

2009-08-18 Thread Eduardo Leoni
## if x is a matrix this should work
library(reshape)
x <- structure(c(36.41099, 73.60079, 171.94, 67.48221, 131.917, 85.17079,
0.4015699, 9.4656186, 9.201167, 11.7657645, 14.4986667, 17.3150434,
35.1, 50, 153.5, 40, 97, 57.3, 36.2, 67, 166.5, 60, 122,
70.9, 36.5, 73, 173, 68, 132, 83.1, 36.7, 80, 176.25, 75,
140, 100, 37.1, 95, 190, 97, 185, 122.5, 89, 253, 20, 253, 253,
89), .Dim = c(6L, 8L), .Dimnames = list(c("BODY_TEMPERATURE",
"DIASTOLIC_BLOOD_PRESSURE", "HEIGHT", "PULSE_RATE", "SYSTOLIC_BLOOD_PRESSURE",
"WEIGHT"), c("mean", "sd", "X0.", "X25.", "X50.", "X75.", "X100.",
"n")))

melt(x)

## if it is a data.frame, read the documentation for the reshape package.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose a dataset

2009-08-18 Thread Rolf Turner


You mean ***transform*** a dataset, not ``transpose''.  Transposition
is something done to a matrix.  If you do not get your terminology
straight, no one can help you.

You may get some mileage out of the reshape() function; possibly you
may need the more elaborate facilities in the reshape package.

cheers,

Rolf Turner

On 18/08/2009, at 4:00 PM, rajclinasia wrote:



Hi Everyone,

I have a dataset like this

  mean sd0%
25%   50%

75%  100%   n
BODY TEMPERATURE  36.41099  0.4015699  35.1  36.2  36.5
36.7  37.1  89
DIASTOLIC BLOOD PRESSURE  73.60079  9.4656186  50.0  67.0  73.0
80.0  95.0 253
HEIGHT   171.94000  9.2011670 153.5 166.5 173.0
176.25000 190.0  20
PULSE RATE67.48221 11.7657645  40.0  60.0  68.0
75.0  97.0 253
SYSTOLIC BLOOD PRESSURE  131.91700 14.4986667  97.0 122.0 132.0
140.0 185.0 253
WEIGHT85.17079 17.3150434  57.3  70.9  83.1
100.0 122.5  89

now i want to transpose this dataset like

BODY TEMPERATURE  mean 36.41099
  sd 0.4015699
  0%35.1
  25%  36.222
  50%  36.5
  75%  36.667
  100% 37.1
  n89

DIASTOLIC BLOOD PRESSURE  mean
  sd
  0%
  25%
 50%
 75%
 100%
  n
   etc.
if possible please send me the code. it will be very helpful us.

Thanks in Advance.

--
View this message in context: http://www.nabble.com/Transpose-a- 
dataset-tp25018071p25018071.html

Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting- 
guide.html

and provide commented, minimal, self-contained, reproducible code.



##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose a dataset

2009-08-18 Thread S Ellison
Does ??transpose help
(for example, leading to ?t for 'transpose') 



>>> rajclinasia  18/08/2009 05:00:00 >>>

Hi Everyone,

I have a dataset like this

  mean sd0%   25%  
50%  
75%  100%   n
BODY TEMPERATURE  36.41099  0.4015699  35.1  36.2  36.5 
36.7  37.1  89
DIASTOLIC BLOOD PRESSURE  73.60079  9.4656186  50.0  67.0  73.0 
80.0  95.0 253
HEIGHT   171.94000  9.2011670 153.5 166.5 173.0
176.25000 190.0  20
PULSE RATE67.48221 11.7657645  40.0  60.0  68.0 
75.0  97.0 253
SYSTOLIC BLOOD PRESSURE  131.91700 14.4986667  97.0 122.0 132.0
140.0 185.0 253
WEIGHT85.17079 17.3150434  57.3  70.9  83.1
100.0 122.5  89

now i want to transpose this dataset like

BODY TEMPERATURE  mean 36.41099
  sd 0.4015699
  0%35.1
  25%  36.222
  50%  36.5
  75%  36.667
  100% 37.1
  n89

DIASTOLIC BLOOD PRESSURE  mean
  sd
  0%
  25%
 50%
 75%
 100%
  n
   etc.
if possible please send me the code. it will be very helpful us.

Thanks in Advance.

-- 
View this message in context:
http://www.nabble.com/Transpose-a-dataset-tp25018071p25018071.html 
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose a dataset

2009-08-18 Thread jim holtman
Is this what you want:

> x
  mean sd   X0.  X25.  X50.
  X75. X100.   n
BODY_TEMPERATURE  36.41099  0.4015699  35.1  36.2  36.5
36.7  37.1  89
DIASTOLIC_BLOOD_PRESSURE  73.60079  9.4656186  50.0  67.0  73.0
80.0  95.0 253
HEIGHT   171.94000  9.2011670 153.5 166.5 173.0
176.25000 190.0  20
PULSE_RATE67.48221 11.7657645  40.0  60.0  68.0
75.0  97.0 253
SYSTOLIC_BLOOD_PRESSURE  131.91700 14.4986667  97.0 122.0 132.0
140.0 185.0 253
WEIGHT85.17079 17.3150434  57.3  70.9  83.1
100.0 122.5  89
> t(x)
  BODY_TEMPERATURE DIASTOLIC_BLOOD_PRESSURE HEIGHT PULSE_RATE
SYSTOLIC_BLOOD_PRESSUREWEIGHT
mean36.410990073.600790 171.94   67.48221
 131.91700  85.17079
sd   0.4015699 9.465619   9.201167   11.76576
  14.49867  17.31504
X0. 35.10050.00 153.50   40.0
  97.0  57.3
X25.36.20067.00 166.50   60.0
 122.0  70.9
X50.36.50073.00 173.00   68.0
 132.0  83.1
X75.36.70080.00 176.25   75.0
 140.0 100.0
X100.   37.10095.00 190.00   97.0
 185.0 122.5
n   89.000   253.00  20.00  253.0
 253.0  89.0
>


Also when sending example data, used 'dput'; makes it easier to access it:

> dput(x)
structure(list(mean = c(36.41099, 73.60079, 171.94, 67.48221,
131.917, 85.17079), sd = c(0.4015699, 9.4656186, 9.201167, 11.7657645,
14.4986667, 17.3150434), X0. = c(35.1, 50, 153.5, 40, 97, 57.3
), X25. = c(36.2, 67, 166.5, 60, 122, 70.9), X50. = c(36.5,
73, 173, 68, 132, 83.1), X75. = c(36.7, 80, 176.25, 75, 140,
100), X100. = c(37.1, 95, 190, 97, 185, 122.5), n = c(89L, 253L,
20L, 253L, 253L, 89L)), .Names = c("mean", "sd", "X0.", "X25.",
"X50.", "X75.", "X100.", "n"), class = "data.frame", row.names =
c("BODY_TEMPERATURE",
"DIASTOLIC_BLOOD_PRESSURE", "HEIGHT", "PULSE_RATE", "SYSTOLIC_BLOOD_PRESSURE",
"WEIGHT"))
>


On Tue, Aug 18, 2009 at 12:00 AM, rajclinasia wrote:
>
> Hi Everyone,
>
> I have a dataset like this
>
>                                      mean         sd    0%       25%   50%
> 75%  100%   n
> BODY TEMPERATURE          36.41099  0.4015699  35.1  36.2  36.5
> 36.7  37.1  89
> DIASTOLIC BLOOD PRESSURE  73.60079  9.4656186  50.0  67.0  73.0
> 80.0  95.0 253
> HEIGHT                   171.94000  9.2011670 153.5 166.5 173.0
> 176.25000 190.0  20
> PULSE RATE                67.48221 11.7657645  40.0  60.0  68.0
> 75.0  97.0 253
> SYSTOLIC BLOOD PRESSURE  131.91700 14.4986667  97.0 122.0 132.0
> 140.0 185.0 253
> WEIGHT                    85.17079 17.3150434  57.3  70.9  83.1
> 100.0 122.5  89
>
> now i want to transpose this dataset like
>
> BODY TEMPERATURE  mean 36.41099
>                              sd     0.4015699
>                              0%    35.1
>                              25%  36.222
>                              50%  36.5
>                              75%  36.667
>                              100% 37.1
>                              n        89
>
> DIASTOLIC BLOOD PRESSURE  mean
>                                          sd
>                                          0%
>                                          25%
>                                         50%
>                                         75%
>                                         100%
>                                          n
>                                                       etc.
> if possible please send me the code. it will be very helpful us.
>
> Thanks in Advance.
>
> --
> View this message in context: 
> http://www.nabble.com/Transpose-a-dataset-tp25018071p25018071.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transpose a dataset

2009-08-18 Thread rajclinasia

Hi Everyone,

I have a dataset like this

  mean sd0%   25%   50% 
 
75%  100%   n
BODY TEMPERATURE  36.41099  0.4015699  35.1  36.2  36.5 
36.7  37.1  89
DIASTOLIC BLOOD PRESSURE  73.60079  9.4656186  50.0  67.0  73.0 
80.0  95.0 253
HEIGHT   171.94000  9.2011670 153.5 166.5 173.0
176.25000 190.0  20
PULSE RATE67.48221 11.7657645  40.0  60.0  68.0 
75.0  97.0 253
SYSTOLIC BLOOD PRESSURE  131.91700 14.4986667  97.0 122.0 132.0
140.0 185.0 253
WEIGHT85.17079 17.3150434  57.3  70.9  83.1
100.0 122.5  89

now i want to transpose this dataset like

BODY TEMPERATURE  mean 36.41099
  sd 0.4015699
  0%35.1
  25%  36.222
  50%  36.5
  75%  36.667
  100% 37.1
  n89

DIASTOLIC BLOOD PRESSURE  mean
  sd
  0%
  25%
 50%
 75%
 100%
  n
   etc.
if possible please send me the code. it will be very helpful us.

Thanks in Advance.

-- 
View this message in context: 
http://www.nabble.com/Transpose-a-dataset-tp25018071p25018071.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose array

2009-02-24 Thread Peter Dalgaard

MarcioRibeiro wrote:

Hi Listers,
Is there a way that I can transpose an array...
Suppose I have the following array...

x<-array(c(1,2,3,4),dim=c(1,2,2))
, , 1
 [,1] [,2]
[1,]12
, , 2
 [,1] [,2]
[1,]34

And I would like to get the following result...
, , 1
 [,1] 
[1,]1

[,2]2
, , 2
 [,1] [,2]
[1,]3
[,2]4

Thanks in advance,
Marcio


I think you're looking for

aperm(x,c(2,1,3))

--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transpose array

2009-02-24 Thread Greg Snow
Try aperm(x, c(2,1,3))

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of MarcioRibeiro
> Sent: Tuesday, February 24, 2009 9:50 AM
> To: r-help@r-project.org
> Subject: [R] Transpose array
> 
> 
> Hi Listers,
> Is there a way that I can transpose an array...
> Suppose I have the following array...
> 
> x<-array(c(1,2,3,4),dim=c(1,2,2))
> , , 1
>  [,1] [,2]
> [1,]12
> , , 2
>  [,1] [,2]
> [1,]34
> 
> And I would like to get the following result...
> , , 1
>  [,1]
> [1,]1
> [,2]2
> , , 2
>  [,1] [,2]
> [1,]3
> [,2]4
> 
> Thanks in advance,
> Marcio
> --
> View this message in context: http://www.nabble.com/Transpose-array-
> tp22184286p22184286.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transpose array

2009-02-24 Thread MarcioRibeiro

Hi Listers,
Is there a way that I can transpose an array...
Suppose I have the following array...

x<-array(c(1,2,3,4),dim=c(1,2,2))
, , 1
 [,1] [,2]
[1,]12
, , 2
 [,1] [,2]
[1,]34

And I would like to get the following result...
, , 1
 [,1] 
[1,]1
[,2]2
, , 2
 [,1] [,2]
[1,]3
[,2]4

Thanks in advance,
Marcio
-- 
View this message in context: 
http://www.nabble.com/Transpose-array-tp22184286p22184286.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Transpose and replicate

2008-11-28 Thread Alex99


Hi all,
I used the "replicate" function to make 2 samples from file test with 5
records in each sample and saved the output in "result".

result=replicate(2,test[,sample(colnames(test),5,replace =
FALSE)],simplify=FALSE)

now I need to transpose each sample, but when I use:

t(result) 

or  

result=t(replicate(2,test[,sample(colnames(test),5,replace =
FALSE)],simplify=FALSE))

I get this:

[,1] [,2]   [,3][,4] [,5]   
[1,] Integer,300 Integer,300 Integer,300 Integer,300 Integer,300

anyone has any idea how can I fix it?
Thanks


-- 
View this message in context: 
http://www.nabble.com/Transpose-and-replicate-tp20735722p20735722.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose dataset

2008-03-12 Thread Daniel Malter
if x is your data: t(x) 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Felipe Carrillo
Gesendet: Wednesday, March 12, 2008 8:19 PM
An: [EMAIL PROTECTED]
Betreff: [R] transpose dataset

Hi all:
How can I transpose this dataset from column to row
idweek   value
1  5   51
2  6   73
3  7   41
4  8   22
5  9   83
6  10  55
7  11  42
to something like this...
id1  2  3  4  5  6  7
week  5  6  7  8  9  10 11
value 51 73 41 22 83 55 42

Felipe D. Carrillo
  Fishery Biologist
  US Fish & Wildlife Service
  California, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] transpose dataset

2008-03-12 Thread Felipe Carrillo
Hi all:
How can I transpose this dataset from column to row
idweek   value
1  5   51
2  6   73
3  7   41
4  8   22
5  9   83
6  10  55
7  11  42
to something like this...
id1  2  3  4  5  6  7
week  5  6  7  8  9  10 11
value 51 73 41 22 83 55 42

Felipe D. Carrillo
  Fishery Biologist
  US Fish & Wildlife Service
  California, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.