2 1 1 2 1 2 1 1 1
# $ X5: Factor w/ 2 levels "0","1": 1 1 2 2 2 2 1 1 2 2
A.K.
----- Original Message -----
From: brunosm
To: r-help@r-project.org
Cc:
Sent: Friday, October 19, 2012 10:15 AM
Subject: Re: [R] Matrix to data.frame with factors
Thanks a lot!
--
View th
Obrigado Rui, é isso mesmo ;)
--
View this message in context:
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730p4646757.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https:
Thanks a lot!
--
View this message in context:
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730p4646756.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/m
On Oct 19, 2012, at 16:07 , Rui Barradas wrote:
> Hello,
>
> Try the following.
>
> x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
> y <- data.frame(apply(x, 2, factor))
> str(y)
>
> Hope this helps,
Another way, possibly more easily generalized:
x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
y
Well, strictly speaking, this is still doing it "one variable at a
time." The interpreted loop is hidden, but it's still happening.
A loop free but clumsier approach is:
y <- data.frame(matrix(as.character(x),nrow = nrow(x)))
## Note also that the original column names will be lost and will have
Hello,
Try the following.
x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
y <- data.frame(apply(x, 2, factor))
str(y)
Hope this helps,
Rui Barradas
Em 19-10-2012 12:04, brunosm escreveu:
Hi all,
I have a matrix with 100 variables: each variable as a value of 0 or 1.
What i want to do is conver
Hi all,
I have a matrix with 100 variables: each variable as a value of 0 or 1.
What i want to do is convert this matrix to a data.frame but convert all the
variables to factors (0 and 1) also.
I know i can do this one variable a time but i have 100 variables...
Any easy way of doing this??
Th
7 matches
Mail list logo