Re: [R] control the conversion of factor to numeric

2011-10-18 Thread R. Michael Weylandt
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

Re: [R] control the conversion of factor to numeric

2011-10-18 Thread Philipp Pagel
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

Re: [R] control the conversion of factor to numeric

2011-10-18 Thread David Winsemius
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

Re: [R] control the conversion of factor to numeric

2011-10-18 Thread Martin Batholdy
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,

Re: [R] control the conversion of factor to numeric

2011-10-18 Thread R. Michael Weylandt
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

[R] control the conversion of factor to numeric

2011-10-18 Thread Martin Batholdy
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