Re: [R] Better way than an ifelse statement?

2010-01-14 Thread Henrique Dallazuanna
Try this: example$X3 - sapply(example$X2, switch, -3, -1, 1, 3) On Thu, Jan 14, 2010 at 5:05 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hello All, I am trying to create a column of weights based off of factor levels from another column.  I am using the weights to calculate L scores.

Re: [R] Better way than an ifelse statement?

2010-01-14 Thread Romain Francois
Or this ; example$X3 - c(-3, -1, 1, 3)[ example$X2 ] Romain On 01/14/2010 11:55 AM, Henrique Dallazuanna wrote: Try this: example$X3- sapply(example$X2, switch, -3, -1, 1, 3) On Thu, Jan 14, 2010 at 5:05 AM, Joshua Wileyjwiley.ps...@gmail.com wrote: Hello All, I am trying to create a

Re: [R] Better way than an ifelse statement?

2010-01-14 Thread Henrique Dallazuanna
This works too: example$X3 - example$X2 * 2 - 5 On Thu, Jan 14, 2010 at 8:55 AM, Henrique Dallazuanna www...@gmail.com wrote: Try this: example$X3 -  sapply(example$X2, switch, -3, -1, 1, 3) On Thu, Jan 14, 2010 at 5:05 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hello All, I am

Re: [R] Better way than an ifelse statement?

2010-01-14 Thread Joshua Wiley
Hello, Thanks for all of your responses. I got a lot of great options that work. Thanks again! Joshua __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

[R] Better way than an ifelse statement?

2010-01-13 Thread Joshua Wiley
Hello All, I am trying to create a column of weights based off of factor levels from another column. I am using the weights to calculate L scores. Here is an example where the first column are scores, the second is my factor and the third I want to be a column of weights. I can do what I want

Re: [R] Better way than an ifelse statement?

2010-01-13 Thread Ista Zahn
There is a recode function in the Hmisc package that might help: library(Hmisc) example$X3 - recode(example$X2, 1:4, c(-3,-1,1,3)) -Ista On Thu, Jan 14, 2010 at 2:05 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hello All, I am trying to create a column of weights based off of factor levels