Skip to content

Instantly share code, notes, and snippets.

@mgechev
Created March 8, 2011 11:58
Show Gist options
  • Save mgechev/860195 to your computer and use it in GitHub Desktop.
Save mgechev/860195 to your computer and use it in GitHub Desktop.
Statistics - 08.03.2011
x2 = c(2,3,0,3,1,0,0,1)
max(x2) #max element in the vector x2
min(x2) #min -//-
x2 == 3
x2 == 0
which(x2 == 3)
n=length(x2)
n
pages=1:n
pages
pages[x2==3] #print all indexes where the element with this index is 3
(1:length(x2))[x2 == max(x2)]
sum(x2) #sum all vector elements
sum(x2>0) #return how many elements are greater than zero
x1 = c(6,5,1,4,0,8,9,2)
x1 - x2
x2 - x1
#x3 = c(4,0,1) !!!!!!!!!WRONG!!!!!!!!!
#x3 - x1
#Adding elements to vector
y = c(48, 49, 51, 50, 49, 41, 40, 38, 35, 40)
y
y = c(y, 48, 49, 51, 50, 49)
y
y = c(1, 2, 3, y, 5, 6)
y
y = c(1, 5, 10, y)
y
length(y)
y[16] = 100
y
y[17:20] = c(0,0,0,0)
y
#Creating tables
#data.entry(y)
#y = de(y)
?whale
whale = c(74, 122, 235, 111, 292, 111, 211, 133, 156, 79)
whale
#Standartno otklonenie
#SD(x) = sqrt((1/(n-1))*Sum((xi - x(4erta))^2))
#x(4erta) == mean(x)
sqrt(var(whale))
sd(whale)
sqrt(sum((whale-mean(whale))^2 )/(length(whale)-1))
std = function(x)sqrt(var(x))
std(whale)
#Bar charts
#Beer
#1) Domestic can
#2) Domestic bottle
#3) Microbew
#4) Import
beer = scan() #after that barplot(beer), barplot(table(beer)), table(beer), barplot(table(beer)/length(beer)/25), table(beer)/length(beer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment