Re: [R] How to create a new variable based on parts of another character variable: A generalization

2011-10-24 Thread Petr PIKAL
Hi Bert I am aware of factor features and frankly speaking I consider them quite usefull despite of prevalent preference to character vectors. For the OP question seems to me that ifelse construction is appropriate, based on his statement he has 2 strings which shall be converted to another two

Re: [R] How to create a new variable based on parts of another character variable: A generalization

2011-10-24 Thread Bert Gunter
... Well, this works in this simple case, but is too clumsy for a general formulation of this problem: given a "dictionary" consisting of two character vectors of unique "names" (or two columns in a data frame), x and y, how does one convert a factor z with levels in x into the corresponding equi

Re: [R] How to create a new variable based on parts of another character variable.

2011-10-24 Thread Petr PIKAL
Hi If you want to get rid of regular expressions at all and your A values start AWI for Arctic and UFT for boreal you can DF$D <- ifelse(substr(DF$A, 1,1) == "A", "Arctic", "Boreal") Regards Petr > > Hello, > I am just starting with R and I am having a (most probably) stupid problem > by c

Re: [R] How to create a new variable based on parts of another character variable.

2011-10-24 Thread Jim Lemon
On 10/24/2011 12:35 AM, Philipp Fischer wrote: Hello, I am just starting with R and I am having a (most probably) stupid problem by creating a new variable in a data.frame based on a part of another character variable. I have a data frame like this one: A B

Re: [R] How to create a new variable based on parts of another character variable.

2011-10-23 Thread jim holtman
Use regular expressions ?grepl On Sunday, October 23, 2011, Philipp Fischer wrote: > Hello, > I am just starting with R and I am having a (most probably) stupid problem by creating a new variable in a data.frame based on a part of another character variable. > > I have a data frame like this one

[R] How to create a new variable based on parts of another character variable.

2011-10-23 Thread Philipp Fischer
Hello, I am just starting with R and I am having a (most probably) stupid problem by creating a new variable in a data.frame based on a part of another character variable. I have a data frame like this one: A B C AWI-test1 1 i AWI-test5