Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Assigning to an object the values that span from a column to another

As per the title, I am trying to make a list of columns from the anscombe dataset, but I want to avoid having to repeat columns like

var_esplicative <- list(anscombe$x1, anscombe$x2, anscombe$x3, anscombe$x4)

So I tried doing something like this var_esplicative <- (anscombe$x1:$x4) to take all the columns ranging from x1 to x4. Nonetheless to say, it didn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use as.list with an indexed dataframe.

as.list(anscombe[, 1:4])

$x1
 [1] 10  8 13  9 11 14  6  4 12  7  5

$x2
 [1] 10  8 13  9 11 14  6  4 12  7  5

$x3
 [1] 10  8 13  9 11 14  6  4 12  7  5

$x4
 [1]  8  8  8  8  8  8  8 19  8  8  8
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading