B R commands

Her kommer en liste over de mest anvendte kommandoer i R.

I foerste omgang kan du benytte denne hjemmeside med oversigt over R kommandoer.

Siden her kommer til at ligne den på linket men er nedenunder ikke færdig.


This chapter contains a brief overview of some of the most common functions we are using in our courses. Another page you might useful is www.statmethods.net that contains a short and clear presentation of many of the commands given below.


Indlæs SundBy data fra web

d <- read.csv("https://biostat.ku.dk/R/data/sundby0_English.csv")

virker det ikke (for enkelte RegionH computere kan der være problemer), så følg fremgangsmåden beskrevet i kap 4.3. Eksemplerne i tabellerne nedenfor virker på SundBy data.

B.1 Viewing data

Command Description.and.examples
head( x, n) Prints the first 6 lines of a vector or a data frame. The additional argument n specifies the number of lines to be printed.
head( d$wgt ), head( d ) or head( d, 12 )
View( x ) Shows a data frame in spreadsheet style.
subset( x, subset ) Returns a subset of a data frame with rows fulfilling the logical condition specified in the subset argument.
subset( d, wgt>100 ) or subset( d, wgt==65 )

B.2 Data manipulations

Command Description
cut( x, breaks, labels ) Divides a numeric variable x into categories. Cut points are specified in the breaks argument. The labels argument is used to specify informative category names. More details in Section 5.4.2.
Example:
cut( d$age, breaks=c(17,45,65,88),
  levels=c('young','middle aged','older'))

B.3 Working with vectors