Sie sind auf Seite 1von 3

Exploring the R console

> 15.3 * 5
[1] 76.5
>
The >sign is the prompt sign. It means that the R console is ready to accept
commands
The [1] tells us that this is the first element of the output (there is only one
element in this example).
___________________________________________________________________________________
______________________
> 15.3 * 5; 3*(4+5)
[1] 76.5
[1] 27

If one command is complete at the end of the line, R is ready to accept the next
command on
the next line.
___________________________________________________________________________________
______________________

Functions and objects


Instead of arithmetic signs you can use
inbuilt
functions such as mean, log(), sqrt(), and sin()
Example:
sqrt(30)
[1] 5.477226
x <-5+39 4*x
[1] 176
sqrt(x)
[1] 6.63325
___________________________________________________________________________________
________________________
mean(c(0,6,8,3,NA,3,6,6), na.rm=TRUE)
[1] 4.571429
na.rm=TRUE (NA-remove is true)
_____________________________________________________
Data form
eight <-c(60,72,57,90,95,72)
> height <-c(1.75,1.80,1.65,1.90,1.74,1.91)
> sex <-rep(c("female", "male"), each = 3) # female male female male remove each
> smoking <-rep(c("TRUE","FALSE"), 3)
> data <-data.frame(weight, height, sex, smoking); data

Reading data from a file


# general function read.table
read.table(file, header
=T)
# default sep="" (space)
# to read a comma
-
separatedfile
read.table("D:/birds.txt", header=T, sep=",")

Name Age
1 1 8
2 2 4
3 3 4
> head(k,1)
Name Age
1 1 8
2 2 4
3 3 4
> Str(k)
Error in Str(k) : could not find function "Str"
> str(k)
'data.frame': 3 obs. of 2 variables:
$ Name: int 1 2 3
$ Age : int 8 4 4
___________________________________________________________________________________
___________
summary(data)
Max,Min,..........
___________________________________________________________________________________
________

Chose spesific value or row from your table

________________________________________________________________________
k[2,1] row 2 coulm 1
dat[,c(2,4)]# second and fourth column

k[,1]
[1] Karim Ahmed Ali
Levels: Ahmed Ali Karim
> table(k$Name,k$Age)

4 4.5 8
Ahmed 1 0 0
Ali 0 1 0
Karim 0 0 1
___________________________________________________________________________________
________
tapply(dat$P8, dat$sex, mean)
___________________________________________________________________________________
_____

an <- function() {

i<-1

for(i in 1:5)

{
if(i<=x){ if(Stage=="Dairy"){ print(y[i]*5)}
else if (Stage=="calf"){print(y[i]*5)}
}
}
}

Das könnte Ihnen auch gefallen