[R] Ifelse statements and combining columns

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Mon Jul 24 14:57:58 CEST 2017


Not a reproducible example, so a bit of guessing here, but

a) don't try to assign results to variables inside the ifelse. That is,  remove all the single-equals signs and "test" variables. If you really need to conditionally assign variables then use "if"... but chances are good you don't need that. 

b) "closure" is effectively another word for"function"... functions like cbind are called with argument lists delimited by parentheses, not brackets, and having a missing argument to the cbind function will be of no use. 
-- 
Sent from my phone. Please excuse my brevity.

On July 24, 2017 5:23:57 AM PDT, Kirsten Morehouse <kmoreho1 at swarthmore.edu> wrote:
>Hi everyone,
>
>I'm having some trouble with my ifelse statements.
>
>I'm trying to put 12 conditions within 3 groups. Here is the code I
>have so
>far:
>
>dat$cond <- ifelse(test = dat$cond == "cond1" | dat$cond == "cond2"  |
>dat$cond == "cond3" dat$cond == "cond4"
>                   yes = "Uniform"
>                   no = ifelse(test = dat$cond == "cond5" | dat$cond ==
>"cond6") | dat$cond == "cond7" dat$cond == "cond8"
>                   yes = "Biased Low"
>                   no = "Biased High" )
>
>
>I keep getting an error statement about an invalid ). I've tried
>several
>permutations to fix, but without luck.
>
>Also, can anyone help me bind columns together? I've tried:
>
> cbind[, c(15:25)] but get the error:  object of type 'closure' is not
>subsettable
>
>Thank you in advance!
>
>Kirsten
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list