Advertisement
Five_NT

Laborator #2

Apr 12th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1.  
  2. #I_1
  3. >x = scan("sample1.txt")
  4. > stem(x)
  5.  
  6. #I_2
  7. > tablou=read.csv("unemploy2012.csv", header=T, sep=";");
  8. > rate=tablou[['rate']];
  9. > interval=c(0,seq(4,14,2),300);
  10. > hist(rate, breaks=interval, right=F);
  11.  
  12. #I_3
  13. > tablou=read.csv("life_expect.csv", header=T, sep=",");
  14. > country=tablou[['country']];
  15. > male=tablou['male'];
  16. > male=tablou[['male']];
  17. > female=tablou[['female']];
  18. > interval=seq(min(male),max(male), length=8);
  19. > hist(male, breaks=interval, right=F);
  20. > interval=seq(min(female),max(female), length=8);
  21. > hist(female, breaks=interval, right=F);
  22.  
  23. #II_1
  24. >x=scan("sample1.txt");
  25. >mean(x);
  26. >median(x);
  27.  
  28. #II_2
  29. tablou=read.csv("life_expect.csv", header=T, sep=",");
  30. country=tablou[['country']];
  31.  
  32. barbati=tablou[['male']];
  33. femei=tablou[['female']];
  34. mean(barbati);
  35. median(barbati);
  36. mean(femei);
  37. median(femei);
  38.  
  39. #II_3
  40. modul = function(a){
  41. return(names(which(table(a)==max(table(a)))))
  42. }
  43.  
  44. modul (c(1,1,1,3,4,4,4))
  45.  
  46. #III_1
  47. outliers_mean=function(esantion){
  48. m=mean(esantion);
  49. s=sd(esantion);
  50. esantion_nou=vector();
  51. j=0;
  52. for (i in 1:length(esantion))
  53. if (esantion[i]<=m-2*s || esantion[i]>=m+2*s){
  54. j=j+1;
  55. esantion_nou[j]=esantion[i];
  56. }
  57. return (esantion_nou);
  58. }
  59.  
  60. sample = c(1, 91, 38, 72, 13, 27, 11, 85, 5, 22, 20, 19, 8, 17, 11, 15, 13, 23, 14, 17)
  61. outliers_mean(sample)
  62.  
  63. #III_2
  64. outliers_iqr=function(esantion){
  65. q1=as.vector(quantile(esantion))[2];
  66. q3=as.vector(quantile(esantion))[4];
  67. iqr=q3-q1;
  68. esantion_nou=vector();
  69. j=0;
  70. for (i in 1:length(esantion))
  71. if (esantion[i]<=q1-iqr*1.5 || esantion[i]>=q3+iqr*1.5){
  72. j=j+1;
  73. esantion_nou[j]=esantion[i];
  74. }
  75. return (esantion_nou);
  76. }
  77.  
  78. #III_3
  79. outliers_mean(esantion);
  80. outliers_iqr(esantion);
  81. summary(esantion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement