Re: [R] string/character to number

From: Søren Højsgaard <>
Date: Thu 23 Jun 2005 - 07:49:58 EST

This works

x<-c("a", "b", "a", "b")
x[x=="b"]<- -1

[1] 1 -1 1 -1

Fra: på vegne af Jake Michaelson Sendt: on 22-06-2005 23:35
Emne: [R] string/character to number

I did a very quick search of the archive and couldn't find a readily available answer to this one:

I'd like to convert, for example:

c("a", "b", "a", "b")


c(1, -1, 1, -1)

In the case of the first vector, it may be any length, but will always only have two unique values. It must always be replaced by corresponding values of 1 and -1.

Any thoughts?

Thanks in advance,

Jake mailing list PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Thu Jun 23 07:54:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:57 EST