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 =
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
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 swap
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
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
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.
--
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
6
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 z fac
1 1 1
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]
(d -
9 matches
Mail list logo