Aan de slagGa gratis aan de slag

Select elements in objects

This exercise focuses on extracting different elements from objects in R. Your workspace environment includes the objects created previously: two numeric vectors numvec1 and numvec2, one character vector charvec, a matrix nummtx, and a dataframe dataframe. Type the name of each object in the console to view them again if you wish. The dplyr package is also loaded.

You will get experience selecting elements from each type of object (vector, matrix, and dataframe).

Deze oefening maakt deel uit van de cursus

R For SAS Users

Cursus bekijken

Oefeninstructies

  • Select the 2nd element in vector charvec
  • Select the 2nd column of matrix nummtx
  • Pull column numvec1 from dataframe dataframe assign it to an object named id
  • Pull column charvec from dataframe dataframe determine the class of charvec

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Select the 2nd element in vector charvec
charvec[___]

# Select the 2nd column of matrix nummtx
nummtx[___]

# Pull column numvec1 from dataframe assign it to id
___ <- ___ %>% 
  ___

# Pull column charvec from dataframe and determine the class of charvec
___ %>% 
  ___ %>% 
  ___
Code bewerken en uitvoeren