Re: [R] Swap rows and columns in a matrix

2012-10-30 Thread David Winsemius
> > > > - Original Message - > From: David Winsemius > To: Haris Rhrlp > Cc: "R-help@r-project.org" > Sent: Tuesday, October 30, 2012 6:51 PM > Subject: Re: [R] Swap rows and columns in a matrix > > > On Oct 30, 2012, at 11:59 AM, Haris Rh

Re: [R] Swap rows and columns in a matrix

2012-10-30 Thread arun
HI David, Seems like a closing bracket is needed. mat[, sample(dim(mat)[2]) ]    ^^^ A.K. - Original Message - From: David Winsemius To: Haris Rhrlp Cc: "R-help@r-project.org" Sent: Tuesday, October 30, 2012 6:51 PM Subject: Re: [R]

Re: [R] Swap rows and columns in a matrix

2012-10-30 Thread David Winsemius
On Oct 30, 2012, at 11:59 AM, Haris Rhrlp wrote: > Dear R users, > > I want a help to write an algorithm for swapping rows and columns in a matrix > This will "shuffle" columns, although 'randomly permute' is the more common word for this;operation: set.seed(123) mat[, sample(dim(mat)[2] ]

Re: [R] Swap rows and columns in a matrix

2012-10-30 Thread Rolf Turner
On 31/10/12 07:59, Haris Rhrlp wrote: Dear R users, I want a help to write an algorithm for swapping rows and columns in a matrix thanks in advance ?t (???) cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.et

Re: [R] Swap rows and columns in a matrix

2012-10-30 Thread Federman, Douglas
Does the builtin function 't' work for your needs? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Haris Rhrlp Sent: Tuesday, October 30, 2012 3:00 PM To: R-help@r-project.org Subject: [R] Swap rows and columns in a matr

[R] Swap rows and columns in a matrix

2012-10-30 Thread Haris Rhrlp
Dear R users, I want a help to write an algorithm for swapping rows and columns in a matrix thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] swap hist() colours

2012-09-14 Thread Rui Barradas
Hello, Use ?colorRampPalette nr <- nrow(yes.matrix_11) clrs <- colorRampPalette(c("white", "black"))(nr) barplot(yes.matrix_11, beside =TRUE, ylim=c(0,250), col = clrs) [...etc...] Hope this helps, Rui Barradas Em 14-09-2012 12:33, Robert Pazur escreveu: Hi, i created a set of graphs and wa

[R] swap hist() colours

2012-09-14 Thread Robert Pazur
Hi, i created a set of graphs and want to find out how to swap the bar colours (from white to black) and set it to be default for all graph that i will produce (f.e. for different number of columns). some sugggestions? thanks in advance. here is an example: ## a <-read.

Re: [R] swap

2008-08-22 Thread Patrick Burns
I'm guessing that the following (untested) does what is wanted: function(x) { pos <- sample(length(x), 2, replace=FALSE) x[pos] <- x[ pos[2:1] ] x } Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User")

Re: [R] swap

2008-08-22 Thread Richard . Cotton
> Hello Richie, > I would like to do three (or k) swap steps in each step just 2 ID > recursive swaping > x <- 1:10 > swap <- function(x){ > a <- sample(x,2) > x[x==a[1]] <- swap[2] > x[x==a[2]] <- swap[1] > return(x) > } > swap(swap(swap(x))) -> mix I tried my best with a response be

Re: [R] swap

2008-08-22 Thread jim holtman
Is this what you want: > swap <- function(z){ + a <- sample(length(z), 2) + z[a] <- z[rev(a)] + z + } > swap(1:10) [1] 2 1 3 4 5 6 7 8 9 10 > > swap(1:10) [1] 5 2 3 4 1 6 7 8 9 10 > swap(1:10) [1] 8 2 3 4 5 6 7 1 9 10 > swap(1:10) [1] 2 1 3 4 5 6 7

[R] swap

2008-08-22 Thread amor Gandhi
Hello Richie, I would like to do three (or k) swap steps in each step just 2 ID recursive swaping x <- 1:10 swap <- function(x){   a <- sample(x,2)   x[x==a[1]] <- swap[2]   x[x==a[2]] <- swap[1]   return(x)   }   swap(swap(swap(x))) -> mix   Is this possible? Thanks you in advance! Amor

Re: [R] swap

2008-08-22 Thread Richard . Cotton
> I wonder if there is any swap function in R that does the following: > x <- seq(1,10,12) This just makes x equal to 1. I'm guessing you meant something like x <- 1:10 > x1 <- swap(x) > x1 > 1 8 3 4 5 6 7 2 10 It's not terribly clear what you want swap to do. You can reorder the elements of

[R] swap

2008-08-22 Thread amor Gandhi
Hello everybody,   I wonder if there is any swap function in R that does the following: x <- seq(1,10,12) x1 <- swap(x) x1 1 8 3 4 5 6 7 2 10 Thank you very much!   Amor __ Schutz gegen Massenmails. [[alternative HTML version deleted]

Re: [R] Swap variables in data.frame

2008-06-03 Thread Birgitle
Thanks might be easier in my case because I have so many variables. Could have found this solution on my own. Birgit Rogers, James A [PGRD Groton] wrote: > > > Birgit Lemcke wrote: > >> I have a dataframe and two of my variables are in the wrong position >> and I would like to swap those va

Re: [R] Swap variables in data.frame

2008-06-03 Thread Rogers, James A [PGRD Groton]
Birgit Lemcke wrote: > I have a dataframe and two of my variables are in the wrong position > and I would like to swap those variables. In addition to the other solutions posted, if you prefer to reference the columns by name rather than by index, you could use subset() dat <- data.frame(a =

Re: [R] Swap variables in data.frame

2008-06-02 Thread Birgitle
That works perfect. Thanks a lot Paul! Greets Birgit Paul Smith wrote: > > On Mon, Jun 2, 2008 at 1:04 PM, Birgitle <[EMAIL PROTECTED]> > wrote: >> >> Thanks Paul. >> >> I am not sure if I understood well, but when I do it then I have only two >> columns left: >> >>> L3 <- LETTERS[1:3] >>> (

Re: [R] Swap variables in data.frame

2008-06-02 Thread Paul Smith
On Mon, Jun 2, 2008 at 1:04 PM, Birgitle <[EMAIL PROTECTED]> wrote: > > Thanks Paul. > > I am not sure if I understood well, but when I do it then I have only two > columns left: > >> L3 <- LETTERS[1:3] >> (d <- data.frame(cbind(x=1, y=1:10, z=11:20), fac=sample(L3, 10, >> replace=TRUE))) > x y

Re: [R] Swap variables in data.frame

2008-06-02 Thread Birgitle
Thanks Paul. I am not sure if I understood well, but when I do it then I have only two columns left: > L3 <- LETTERS[1:3] > (d <- data.frame(cbind(x=1, y=1:10, z=11:20), fac=sample(L3, 10, > replace=TRUE))) x y z fac 1 1 1 11 C 2 1 2 12 B 3 1 3 13 B 4 1 4 14 C 5 1 5 15 C

Re: [R] Swap variables in data.frame

2008-06-02 Thread Paul Smith
On Mon, Jun 2, 2008 at 11:59 AM, Blubbele <[EMAIL PROTECTED]> wrote: > > Thanks but it swaps in both cases only the data: > > FemMal_88[c(61,62)]=FemMal_88[c(62,61)] > > > FemMal_88[,c(61,62)]=FemMal_88[,c(62,61)] The following works: d <- data.frame(a=c(1,2),b=c(3,4)) d <- d[,c(2,1)] Paul

Re: [R] Swap variables in data.frame

2008-06-02 Thread Blubbele
Thanks but it swaps in both cases only the data: FemMal_88[c(61,62)]=FemMal_88[c(62,61)] FemMal_88[,c(61,62)]=FemMal_88[,c(62,61)] Greets B. Karl Ove Hufthammer-4 wrote: > > Birgit Lemcke: > >> I have a dataframe and two of my variables are in the wrong position >> and I would like to swa

Re: [R] Swap variables in data.frame

2008-06-02 Thread Karl Ove Hufthammer
Birgit Lemcke: > I have a dataframe and two of my variables are in the wrong position > and I would like to swap those variables. To swap column 1 and 2, try d[c(1,2)]=d[c(2,1)] Note that this is different from d[,c(1,2)]=d[,c(2,1)] which will swap the data, but not the column names. --

[R] Swap variables in data.frame

2008-06-02 Thread Birgit Lemcke
Hello R-user community! I am running R 2.7.0 on a Power Book (Tiger). (I am still R and statistics beginner) I have a problem that is certainly solved very easily but presently I don`t know how. I have a dataframe and two of my variables are in the wrong position and I would like to swa