Re: [R] If statement - copying a factor variable to a new variable

2012-06-29 Thread peter dalgaard
On Jun 28, 2012, at 09:42 , Rui Barradas wrote: Hello, Another way is to use index vectors: v1.factor - c(S,S,D,D,D,NA) v2.factor - c(D,D,S,S,S,S) td2 - test.data - data.frame(v1.factor,v2.factor) for (i in 1:nrow(test.data) ) { [... etc ...] } #End FOR # Create index

Re: [R] If statement - copying a factor variable to a new variable

2012-06-28 Thread Miguel Manese
Hi James, On Thu, Jun 28, 2012 at 12:33 AM, James Holland holland.ag...@gmail.com wrote: I need to look through a dataset with two factor variables, and depending on certain criteria, create a new variable containing the data from one of those other variables. The problem is, R keeps making

Re: [R] If statement - copying a factor variable to a new variable

2012-06-28 Thread Rui Barradas
Hello, Another way is to use index vectors: v1.factor - c(S,S,D,D,D,NA) v2.factor - c(D,D,S,S,S,S) td2 - test.data - data.frame(v1.factor,v2.factor) for (i in 1:nrow(test.data) ) { [... etc ...] } #End FOR # Create index vectors na1 - is.na(v1.factor) na2 - is.na(v2.factor) # Create

Re: [R] If statement - copying a factor variable to a new variable

2012-06-28 Thread James Holland
Yeah, the reason I didn't use ifelse is because I've got multiple variables to manipulate based on the if statement, some factors and some numeric. I have to look at the factor variables, and based on that, either use one series of variables or another. With the multiple if statements I need to

Re: [R] If statement - copying a factor variable to a new variable

2012-06-28 Thread Miguel Manese
On Thu, Jun 28, 2012 at 8:47 PM, James Holland holland.ag...@gmail.com wrote: With the multiple if statements I need to check for, I though for statements with the if/else if conditional statement was better than nested ifelse functions. for () gives you a lot of flexibility at the expense of

[R] If statement - copying a factor variable to a new variable

2012-06-27 Thread James Holland
I need to look through a dataset with two factor variables, and depending on certain criteria, create a new variable containing the data from one of those other variables. The problem is, R keeps making my new variable an integer and saving the data as a 1 or 2 (I believe the levels of the