R: Exercises

From MathWiki

Exercises in R

Table of contents

Inverting a list

Write a function that will transform a list in the form:

  list( a = c("A","B","C"), b = c("A","E"))


  list( A = c('a','b'), B = c('a'), C = c('a'), "E" = 'b') )

Printing data frames

Write a function that turns repeated values in selected columns to blanks. e.g.

  Name      Language     Project
  John      R            proj1
  John      R            proj2
  John      SAS          proj3
  Mary      R            proj4
  Mary      SAS          proj5
  Mary      SAS          proj6

Should print as:

  Name      Language     Project
  John      R            proj1
            SAS          proj3
  Mary      R            proj4
            SAS          proj5

Plotting longitudinal data

Plot trajectories for many subject using plotting character, line style and colour to identify groups.

Plotting fits within groups

Plot adjusted data plus fitted line (i.e. component plus residual plot showing the component and the adjusted data)