SlideServe
Menu
Préférences
© SlideServe · v2026

Learning R hands on

felice avatar
9 diapositives · 178 Views · Jul 10, 2014

Learning R hands on. Organization of Folders:. Class Data folder has datasets (end in . csv or . rda ) Rcode has the scripts of R commands that can cut and pasted into an R window (end in .R) Ppt has the powerpoints. The Basics Rintro.R. Reading in comma separated data

Learning R hands on - slide 1
01 / 9Learning R hands on
1 / 17

Télécharger la présentation

Learning R hands on
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Learning R hands on

  2. Organization of Folders: • Class Data folder has datasets (end in .csvor .rda) • Rcode has the scripts of R commands that can cut and pasted into an R window (end in .R) • Ppt has the powerpoints

  3. The Basics Rintro.R • Reading in comma separated data • Listing a data set or its components • Subscripts • Sequences and combing values (: and “c”) • Creating a new data set with <- • Arithmetic in R • Applying some stats to data • Saving your work

  4. Fooling with the data RintroManipulating.R • Subscripting to get a subset of data • Working with rows and columns • Arithmetic on a column at once Pay attention to where the commas are! e.g. BT2[3,5] BT2[3,] BT2[,5] BT2[,3:5] or BT2[1:10,3:5] These are all different!

  5. Plotting DataRintroPlotting.R • Histogram hist • Adding more features to the plot • Scatterplots using plot • Box plots for several data sets boxplot • Adding text to a scatter plot • Changing the axes scales Build a complicated plot by adding features through several simple steps

  6. Writing functionsRintroFunctions.R • The uses for { } and ( ) • What goes in and what comes out • Listing a function • Optional arguments • Calling a function and assigning its results to a new data set • Review of R arithmetic

  7. More on R programmingRintroProgramming.R • Changing the data type • Looping the for block • if statements and logicals • lists • The apply function

  8. Best Practices in coding • Use informative names for important variables • Comment steps that are not obvious • Break R expressions into several steps for clarity • Many smaller and simple functions are good– avoid functions more than about 50 lines. • Simple is good – overly clever is a good way to introduce bugs! • Add default values and test that will prevent data analysis errors.

  9. The interquartile range function # finds the interquartile range of a vector MyIQR<- function( y,na.rm=FALSE){ if( !is.vector(y) ){ stop(‘data is not a vector’)} # omits NAs if na.rm is TRUE Q25<- quantile( y, .25, na.rm=na.rm) Q75<- quantile( y, .75, na.rm=na.rm) IQR<- Q75 – Q25 return(IQR) }