[R] Creating new variables
jholtman at gmail.com
Sun Oct 11 00:32:18 CEST 2009
If the 'data set' is a dataframe, the following will work:
x$v1 <- ifelse(x$p > 0.4, 1, 0)
x$v2 <- ifelse(x$p > 0.6, 1, 0)
If it is matrix, try
x <- cbind(x, v1=ifelse(x[,'p'] > 0.4, 1, 0), v2=ifelse(x[,'p'] > 0.6, 1, 2))
If helps a lot if you follow the posting rules and provide commented,
minimal, self-contained, reproducible code.
On Sat, Oct 10, 2009 at 6:04 PM, Ashta <sewashm at gmail.com> wrote:
> Hi all,
> I have a data set called x with 200 rows and 12 columns. I want
> create two more columns based on probability. ie
> if p >0 .4 then v1 =1 else v1=0;
> if p >0 .6 then v2 =1 else v2=0;
> Finally x will have 14 variables.
> Can any one show me how to do that?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help