Re: [R] How to create a new variable?

2014-03-01 Thread arun
Hi, Not sure about your expected result.  If you need a logical index as the new variable: ##check str(Food) Food[,-1] - lapply(Food[,-1],function(x) as.numeric(as.character(x)))  str(Food)  Food1 - within(Food,Healthy.food - GRASSI 20)  HFood - Food1[Food1$Healthy.food,-7]  dim(HFood) #[1]

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-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 creating a

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

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

[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

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 philipp.fisc...@awi.de 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