[R] [FORGED] Merging a dataframe after subsetting with respect to several factors

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Fri Jun 14 01:01:59 CEST 2019


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



More information about the R-help mailing list