Use the stringsAsFactors = FALSE argument for read.table() so the
strings will remain factors and then you can convert them directly
yourself.
Michael
On Tue, Oct 18, 2011 at 9:40 AM, Martin Batholdy
wrote:
> Ok, I think that would work – thanks!
>
> However, in my case I read a data.frame via r
On Tue, Oct 18, 2011 at 03:40:27PM +0200, Martin Batholdy wrote:
> Ok, I think that would work – thanks!
>
> However, in my case I read a data.frame via read.table().
> So some of the columns get transformed to factors automatically – > I don't
> generate the factor-variables as in the example, so
On Oct 18, 2011, at 7:35 AM, Martin Batholdy wrote:
Dear R-list,
I currently have to convert a data.frame with several factor-
variables to a numeric matrix.
Now the problem is, that the order of the factor-labels don't match
the order I would like to use.
for example, let's assume I
Ok, I think that would work – thanks!
However, in my case I read a data.frame via read.table().
So some of the columns get transformed to factors automatically –
I don't generate the factor-variables as in the example, so I can't control how
the levels are ordered (or can I?).
On 18.10.2011,
Add levels= to your factor() call.
E.g.,
x1 <- factor(rep(1:4, 5), labels=c("slightly disagree", "disagree",
"agree", "slightly agree"), levels = c(2,1,4,3))
as.numeric(x1)
[1] 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3
Michael
On Tue, Oct 18, 2011 at 7:35 AM, Martin Batholdy
wrote:
> Dear R-lis
Dear R-list,
I currently have to convert a data.frame with several factor-variables to a
numeric matrix.
Now the problem is, that the order of the factor-labels don't match the order I
would like to use.
for example, let's assume I have this factor-variable in my data-frame:
x <- factor(re
6 matches
Mail list logo