[R] Ifelse statements and combining columns

Rui Barradas ruipbarradas at sapo.pt
Mon Jul 24 14:52:00 CEST 2017


Hello,

Your ifelse statement is a mess. I cannot make sense of it. Let me try 
to explain where I've lost it.

dat$cond <- ifelse(test = dat$cond == "cond1"
This is already very bad, do you mean dat$cond == "cond1" ?
Maybe you mean that condition OR the others below, but then there's one 
'|' missing, just before the last condition.

| dat$cond == "cond2"  |
    dat$cond == "cond3" dat$cond == "cond4"

After this your code should have a comma. It's missing.
Maybe you can tell us in plain english the conditions your ifelse should 
process.

Hope this helps,

Rui Barradas

Em 24-07-2017 13:23, Kirsten Morehouse escreveu:
> 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