[R] if/else help

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Sep 21 08:57:54 CEST 2016


Get rid of the commas? Get rid of the get() function call? Get rid of the cbind() function call?  Post using plain text format so the HTML doesn't screw up code? Read the Posting Guide? All of these ideas have merit IMHO...
-- 
Sent from my phone. Please excuse my brevity.

On September 20, 2016 12:31:47 PM PDT, "Crombie, Burnette N" <bcrombie at utk.edu> wrote:
>If a data.frame (r4) does not exist in my R environment, I would like
>to create it before I move on to the next step in my script. How do I
>make that happen?  Here is what I want to do from a code perspective:
>
>if (exists(r4))
>{
>is.data.frame(get(r4))
>}
>else
>{
>a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
>}
>
>Thanks for your help,
>B
>
>	[[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