>
>
>
> - 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
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]
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] ]
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
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
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
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
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.
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")
> 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
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
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
> 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
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]
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
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 =
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]
>>> (
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
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
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
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
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.
--
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
23 matches
Mail list logo