R code_with() function

Asked

Viewed 48 times

3

What does this line of code mean?

with(epilepsy,by(seizures/timeadj,list(treat,expind),mean)) 

the data is from the package faraway.

1 answer

5

The function with is a convenience function that allows you to access the columns of the data.frame without having to repeat the name of data.frame at all times.

The code:

with(epilepsy, by(seizures/timeadj, list(treat,expind), mean))

It’s the same thing:

by(epilepsy$seizures/epilepsy$timeadj, list(epilepsy$treat, epilepsy$expind), mean)

See that without the with you need to repeat the name of data.frame epilepsy every time you reference your columns.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.