On 14/06/19 5:30 AM, Tina Chatterjee wrote:

Hello everyone!
I have the following dataframe(df).

a<-c("a1","a2","a2","a1","a1","a1")
b<-c("b1","b1","b1","b1","b1","b2")
c<-c("c1","c1","c1","c1","c1","c2")
time <- c(runif(6,0,1))

<SNIP>

<rant on>

I know that it's basically harmless, but it drives me nuts when people do things like:

time <- c(runif(6,0,1))

What the <expletive deleted> do you think that the c() construction is doing? ("Hint": Absolutely nothing!!! You get the same result as you'd get from "time <- runif(6,0,1)" --- or, better, time <- runif(6).
Note that 0 and 1 are the *default* values and *need not be specified*!)

The c() function *catenates* a number of objects (usually vectors) together. Modulo a certain amount of over-simplification, applying c() to a single object just returns that object.

(Example of why that's an over-simplification:  if m is a matrix,
c(m) strips away the "dim" attribute of m and you just get the vector of entries of m, strung out in column order. This is however not advised;
see fortunes::fortune("side effects").)

Using c() as you have done indicates that you don't really understand what you're doing, and that's *not* the way to get the best out of R.

<rant off>

cheers,

Rolf

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
R-help@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.

Reply via email to