Vector and matrix with R

Vector and matrix with R

vector, nrow


> url_to_open
[1] "http://finviz.com/export.ashx?v=152&c=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68"
> summary(finviz)
                                                                                         X..DOCTYPE.html.
 \t\t\t                <td><img src=/img/elite/no.png srcset=/img/elite/no_2x.png 2x alt=No></td>   : 24 
 \t\t                </tr>                                                                         : 18 
 \t\t                <tr>                                                                          : 18 
                 </div>                                                                          : 15 
                     </div>                                                                      : 12 
 \t\t\t                <td><img src=/img/elite/yes.png srcset=/img/elite/yes_2x.png 2x alt=Yes></td>:  8 
 (Other)                                                                                         :356 
> clean_numeric <- function(s){
+     s <- gsub("%|\\$|,|\\)|\\(", "", s)
+     s <- as.numeric(s)
+ }
> finviz <- cbind(finviz[,1:6],apply(finviz[,7:68], 2,
+                                    clean_numeric))
Error in `[.data.frame`(finviz, , 1:6) : undefined columns selected
> finviz <- cbind(finviz[,1:6],apply(finviz[,7:68], 2,
+                                    clean_numeric))
Error in `[.data.frame`(finviz, , 1:6) : undefined columns selected
> hist(finviz$Price, breaks=100, main="Price Distribution",
+      xlab="Price")
Error in hist.default(finviz$Price, breaks = 100, main = "Price Distribution",  :
  'x' must be numeric
> industry_avg_prices <-
+     aggregate(Price~Sector+Industry,data=finviz,FUN="mean")
Error in eval(predvars, data, env) : object 'Price' not found
> url <-
+     paste("http://sports.yahoo.com/nfl/stats/byteam?group=Offense&
+ cat=Total&conference=NFL&year=season_",year,"&sort=530&old_category=Total&old_group=Offense")
Error in paste("http://sports.yahoo.com/nfl/stats/byteam?group=Offense&\ncat=Total&conference=NFL&year=season_",  :
  object 'year' not found
> sector_avg <-
+     subset(sector_avg,variable%in%c("Price","P.E","PEG","P.S","P.B"))
Error in subset(sector_avg, variable %in% c("Price", "P.E", "PEG", "P.S",  :
  object 'sector_avg' not found
> a <- c(1, 2, 5, 3, 6, -2, 4)
> b <- c("one", "two", "three")
> c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)
> a <- c(1, 2, 5, 3, 6, -2, 4)
> a[3]
[1] 5
> a[c(1, 3, 5)]
[1] 1 5 6
> a[2:6]
[1]  2  5  3  6 -2
> myymatrix <- matrix(vector, nrow=number_of_rows, ncol=number_of_columns,byrow=logical_value, dimnames=list(
+ char_vector_rownames, char_vector_colnames))
Error in as.vector(x, mode) :
  cannot coerce type 'closure' to vector of type 'any'
> y <- matrix(1:20, nrow=5, ncol=4)
> M <- matrix(1:20, nrow = 5, ncol = 4)
> y
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20
> x<-pretty(c(-5,5),30)
> k<-dnorm(x)
x<-pretty(c(-5,5),30) k<-dnorm(x)
Error: unexpected symbol in "x<-pretty(c(-5,5),30) k"
In addition: Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  "klab" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "kaxs" is not a graphical parameter
3: In doTryCatch(return(expr), name, parentenv, handler) :
  "klab" is not a graphical parameter
4: In doTryCatch(return(expr), name, parentenv, handler) :
  "kaxs" is not a graphical parameter
> x<-pretty(c(-5,5),30)
>  y<-dnorm(x)
> plot(x,y,type ="1",xlab="Normal Daviate",ylab= "Density",yaxs='i')
Error in plot.xy(xy, type, ...) : invalid plot type '1'
> x <- pretty(c(-3,3), 30)
> y <- dnorm(x)
> plot(x, y,
+      type = "l",
+      xlab = "Normal Deviate",
+      ylab = "Density",
+      yaxs = "i"
+ )
> plot(x,y,type ="l",xlab="Normal Daviate",ylab= "Density",yaxs='i')
> pnorm(1.96)
[1] 0.9750021
> lm(mpg~wt, data=mtcars)

Call:
lm(formula = mpg ~ wt, data = mtcars)

Coefficients:
(Intercept)           wt
     37.285       -5.344

> lmfit <- lm(mpg~wt, data=mtcars)
> summary(lmfit)

Call:
lm(formula = mpg ~ wt, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max
-4.5432 -2.3647 -0.1252  1.4096  6.8727

Coefficients:
            Estimate Std. Error t value Pr(>|t|) 
(Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
wt           -5.3445     0.5591  -9.559 1.29e-10 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.046 on 30 degrees of freedom
Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446
F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

> plot(lmfit)
Hit <Return> to see next plot:
Hit <Return> to see next plot:
Hit <Return> to see next plot:
Hit <Return> to see next plot:
> cook<-cooks.distance(lmfit)
> plot(cook)
> predict(lmfit, mynewdata)
Error in predict.lm(lmfit, mynewdata) : object 'mynewdata' not found
> help(lm)
> library("vcd", lib.loc="~/R/win-library/3.6")
Loading required package: grid
> a <- c(1, 2, 5, 3, 6, -2, 4)
> b <- c("one", "two", "three")
> c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)
> a[3]
[1] 5
> a[c(1, 3, 5)]
[1] 1 5 6
> a[2:6]
[1]  2  5  3  6 -2
> myymatrix <- matrix(vector, nrow=number_of_rows, ncol=number_of_columns,byrow=logical_value, dimnames=list(
+ char_vector_rownames, char_vector_colnames))
Error in as.vector(x, mode) :
  cannot coerce type 'closure' to vector of type 'any'
> y <- matrix(1:20, nrow=5, ncol=4)
> y
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20
> cells <- c(1,26,24,68)
> rnames <- c("R1", "R2")                                 cnames <- c("C1", "C2")
Error: unexpected symbol in "rnames <- c("R1", "R2")                                 cnames"
> rnames <- c("R1", "R2")
>  cnames <- c("C1", "C2")
> mymatrix <- matrix(cells, nrow=2, ncol=2, byrow=TRUE,
+                    dimnames=list(rnames, cnames))
> mymatrix
   C1 C2
R1  1 26
R2 24 68
> mymatrix <- matrix(cells, nrow=2, ncol=2, byrow=FALSE,
+                    dimnames=list(rnames, cnames))
> mymatrix
   C1 C2
R1  1 24
R2 26 68
>
> x <- matrix(1:10, nrow=2)
> x
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10
> x[2,]
[1]  2  4  6  8 10
> x[,2]
[1] 3 4
> x[,4]
[1] 7 8
> x[1,4]
[1] 7
> x[1, c(4,5)]
[1] 7 9
> myarray <- array(vector, dimensions, dimnames)
Error in as.vector(x, mode) :
  cannot coerce type 'closure' to vector of type 'any'
> dim1 <- c("A1", "A2")
>  dim2 <- c("B1", "B2", "B3")
>  dim3 <- c("C1", "C2", "C3", "C4")
> z <- array(1:24, c(2, 3, 4), dimnames=list(dim1, dim2, dim3))
> z
, , C1

   B1 B2 B3
A1  1  3  5
A2  2  4  6

, , C2

   B1 B2 B3
A1  7  9 11
A2  8 10 12

, , C3

   B1 B2 B3
A1 13 15 17
A2 14 16 18

, , C4

   B1 B2 B3
A1 19 21 23
A2 20 22 24

> patientID <- c(1, 2, 3, 4)
>  age <- c(25, 34, 28, 52)
>  diabetes <- c("Type1", "Type2", "Type1", "Type1")
>  status <- c("Poor", "Improved", "Excellent", "Poor")
> patientdata <-data.frame(patientID, age,diabetes,status)
> patientdata
  patientID age diabetes    status
1         1  25    Type1      Poor
2         2  34    Type2  Improved
3         3  28    Type1 Excellent
4         4  52    Type1      Poor
> patientdata[1,2]
[1] 25
> patientdata[1:2]
  patientID age
1         1  25
2         2  34
3         3  28
4         4  52
> patientdata[c("diabetes", "status")]
  diabetes    status
1    Type1      Poor
2    Type2  Improved
3    Type1 Excellent
4    Type1      Poor
> patientdata$age
[1] 25 34 28 52
> table(patientdata$diabetes, patientdata$status)
     
        Excellent Improved Poor
  Type1         1        0    2
  Type2         0        1    0
> attach(mtcars)
The following object is masked from package:ggplot2:

    mpg

> summary(mpg)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  10.40   15.43   19.20   20.09   22.80   33.90
> plot(mpg, disp)
> plot(mpg, wt)
> detach(mtcars)
 dnorm(x = 3, mean = 2, sd = 5)
[1] 0.07820854
> pnorm(q = 3, mean = 2, sd = 5)
[1] 0.5792597
> qnorm(p = 0.975, mean = 2, sd = 5)
[1] 11.79982
> rnorm(n = 10, mean = 2, sd = 5)
 [1]  8.725094 -2.190330  2.573350 -7.649668
 [5]  6.420524  2.465019  4.561855 -8.622215
 [9]  7.883495  5.382970
> dbinom(x = 6, size = 10, prob = 0.75)
[1] 0.145998
> capt_crisp = data.frame(weight = c(15.5, 16.2, 16.1, 15.8, 15.6, 16.0, 15.8, 15.9, 16.2))
> x_bar = mean(capt_crisp$weight)
> s = sd(capt_crisp$weight)
> mu_0 = 16
> n=9
> t = (x_bar - mu_0) / (s / sqrt(n))
> t
[1] -1.2
> pt(t, df = n - 1)
[1] 0.1322336
> t.test(x = capt_crisp$weight, mu = 16, alternative = c("less"), conf.level = 0.95)

One Sample t-test

data:  capt_crisp$weight
t = -1.2, df = 8, p-value = 0.1322
alternative hypothesis: true mean is less than 16
95 percent confidence interval:
     -Inf 16.05496
sample estimates:
mean of x 
     15.9 

> capt_test_results = t.test(capt_crisp$weight, mu = 16,alternative = c("two.sided"), conf.level = 0.95)
> names(capt_test_results)
 [1] "statistic"   "parameter"   "p.value"    
 [4] "conf.int"    "estimate"    "null.value" 
 [7] "stderr"      "alternative" "method"     
[10] "data.name"  
> capt_test_results$conf.int
[1] 15.70783 16.09217
attr(,"conf.level")
[1] 0.95
> qt(0.975, df = 8)
[1] 2.306004
> c(mean(capt_crisp$weight) - qt(0.975, df = 8) * sd(capt_crisp$weight) / sqrt(9),
+   mean(capt_crisp$weight) + qt(0.975, df = 8) * sd(capt_crisp$weight) / sqrt(9))
[1] 15.70783 16.09217
> x = c(70, 82, 78, 74, 94, 82)
> x
[1] 70 82 78 74 94 82
> n = length(x)
> n
[1] 6
> y = c(64, 72, 60, 76, 72, 80, 84, 68)
> y
[1] 64 72 60 76 72 80 84 68
> x_bar = mean(x)
> s_x = sd(x)
> y_bar = mean(y)
> s_y = sd(y)
> s_p = sqrt(((n - 1) * s_x ^ 2 + (m - 1) * s_y ^ 2) / (n + m - 2))
Error: object 'm' not found
> t = ((x_bar - y_bar) - 0) / (s_p * sqrt(1 / n + 1 / m))
Error: object 's_p' not found
> 1 - pt(t, df = n + m - 2)
Error in pt(t, df = n + m - 2) : object 'm' not found
> t.test(x, y, alternative = c("greater"), var.equal = TRUE)

Two Sample t-test

data:  x and y
t = 1.8234, df = 12, p-value = 0.04662
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
 0.1802451       Inf
sample estimates:
mean of x mean of y 
       80        72 

> t_test_data = data.frame(values = c(x, y),group = c(rep("A", length(x)), rep("B", length(y))))
> t_test_data
   values group
1      70     A
2      82     A
3      78     A
4      74     A
5      94     A
6      82     A
7      64     B
8      72     B
9      60     B
10     76     B
11     72     B
12     80     B
13     84     B
14     68     B
> t.test(values ~ group, data = t_test_data,alternative = c("greater"), var.equal = TRUE)

Two Sample t-test

data:  values by group
t = 1.8234, df = 12, p-value = 0.04662
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
 0.1802451       Inf
sample estimates:
mean in group A mean in group B 
             80              72 

> pnorm(2, mean = 1, sd = sqrt(0.32)) - pnorm(0, mean = 1, sd = sqrt(0.32))
[1] 0.9229001
> set.seed(42)
> num_samples = 10000
> differences = rep(0, num_samples)
> for (s in 1:num_samples) {
+     x1 = rnorm(n = 25, mean = 6, sd = 2)
+     x2 = rnorm(n = 25, mean = 5, sd = 2)
+     differences[s] = mean(x1) - mean(x2)
+ }
> mean(0 < differences & differences < 2)
[1] 0.9222
> hist(differences, breaks = 20,
+      main = "Empirical Distribution of D",
+      xlab = "Simulated Values of D",
+      col = "dodgerblue",
+      border = "darkorange")
> mean(differences)
[1] 1.001423
> var(differences)
[1] 0.3230183
> set.seed(42)
> diffs = replicate(10000, mean(rnorm(25, 6, 2)) - mean(rnorm(25, 5, 2)))
> mean(differences == diffs)
[1] 1
> set.seed(1337)
> mu = 10
> sample_size = 50
> samples = 100000
> x_bars = rep(0, samples)
> for(i in 1:samples){
+     x_bars[i] = mean(rpois(sample_size, lambda = mu))
+ }
> x_bar_hist = hist(x_bars, breaks = 50,
+                   main = "Histogram of Sample Means",
+                   xlab = "Sample Means")
> c(mean(x_bars), mu)
[1] 10.00008 10.00000
> c(var(x_bars), mu / sample_size)
[1] 0.1989732 0.2000000
> c(sd(x_bars), sqrt(mu) / sqrt(sample_size))
[1] 0.4460641 0.4472136
> mean(x_bars > mu - 2 * sqrt(mu) / sqrt(sample_size) &
+          x_bars < mu + 2 * sqrt(mu) / sqrt(sample_size))
[1] 0.95429
> shading = ifelse(x_bar_hist$breaks > mu - 2 * sqrt(mu) / sqrt(sample_size) &
+                      x_bar_hist$breaks < mu + 2 * sqrt(mu) / sqrt(sample_size),
+                  "darkorange", "dodgerblue")
> x_bar_hist = hist(x_bars, breaks = 50, col = shading,main = "Histogram of Sample Means, Two Standard Deviations",
+                   xlab = "Sample Means")
> View(cars)
> str(cars)
'data.frame': 50 obs. of  2 variables:
 $ speed: num  4 4 7 7 8 9 10 10 10 11 ...
 $ dist : num  2 10 4 22 16 10 18 26 34 17 ...
> dim(cars)
[1] 50  2
> nrow(cars)
[1] 50
> ncol(cars)
[1] 2
> plot(dist ~ speed, data = cars,
+      xlab = "Speed (in Miles Per Hour)",
+      ylab = "Stopping Distance (in Feet)", main = "Stopping Distance vs Speed",
+      pch = 20,
+      cex = 2,
+      col = "grey")
> x = cars$speed
> y = cars$dist
> Sxy = sum((x - mean(x)) * (y - mean(y)))
> Sxx = sum((x - mean(x)) ^ 2)
> Syy = sum((y - mean(y)) ^ 2)
> c(Sxy, Sxx, Syy)
[1]  5387.40  1370.00 32538.98
> beta_1_hat = Sxy / Sxx
> beta_0_hat = mean(y) - beta_1_hat * mean(x)
> c(beta_0_hat, beta_1_hat)
[1] -17.579095   3.932409
> library("ggplot2", lib.loc="~/R/win-library/3.6")
> c(1, 3, 5, 7, 8, 9)
[1] 1 3 5 7 8 9
> x=c(1, 3, 5, 7, 8, 9)
> x
[1] 1 3 5 7 8 9
> c(42, "Statistics", TRUE)
[1] "42"         "Statistics" "TRUE"      
> c(42, TRUE)
[1] 42  1
> (y = 1:100)
  [1]   1   2   3   4   5   6   7   8   9  10
 [11]  11  12  13  14  15  16  17  18  19  20
 [21]  21  22  23  24  25  26  27  28  29  30
 [31]  31  32  33  34  35  36  37  38  39  40
 [41]  41  42  43  44  45  46  47  48  49  50
 [51]  51  52  53  54  55  56  57  58  59  60
 [61]  61  62  63  64  65  66  67  68  69  70
 [71]  71  72  73  74  75  76  77  78  79  80
 [81]  81  82  83  84  85  86  87  88  89  90
 [91]  91  92  93  94  95  96  97  98  99 100
> seq(from = 1.5, to = 4.2, by = 0.1)
 [1] 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4
[11] 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4
[21] 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2
> x = 1:9
> rev(x)
[1] 9 8 7 6 5 4 3 2 1
> rbind(x,rev(x),rep(1,9))
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
x    1    2    3    4    5    6    7    8    9
     9    8    7    6    5    4    3    2    1
     1    1    1    1    1    1    1    1    1
> cbind(col_1=x,col_2=rev(x),col_3=rep(1,9))
      col_1 col_2 col_3
 [1,]     1     9     1
 [2,]     2     8     1
 [3,]     3     7     1
 [4,]     4     6     1
 [5,]     5     5     1
 [6,]     6     4     1
 [7,]     7     3     1
 [8,]     8     2     1
 [9,]     9     1     1
> x = 1:9
> y=9:1
> X=matrix(x,3,3)
> Y=matrix(y,3,3)
> X
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> Y
     [,1] [,2] [,3]
[1,]    9    6    3
[2,]    8    5    2
[3,]    7    4    1
> X+Y
     [,1] [,2] [,3]
[1,]   10   10   10
[2,]   10   10   10
[3,]   10   10   10
> X-Y
     [,1] [,2] [,3]
[1,]   -8   -2    4
[2,]   -6    0    6
[3,]   -4    2    8
> X*Y
     [,1] [,2] [,3]
[1,]    9   24   21
[2,]   16   25   16
[3,]   21   24    9
> Y*X
     [,1] [,2] [,3]
[1,]    9   24   21
[2,]   16   25   16
[3,]   21   24    9
> X/Y
          [,1]      [,2]     [,3]
[1,] 0.1111111 0.6666667 2.333333
[2,] 0.2500000 1.0000000 4.000000
[3,] 0.4285714 1.5000000 9.000000
> Y/X
         [,1]      [,2]      [,3]
[1,] 9.000000 1.5000000 0.4285714
[2,] 4.000000 1.0000000 0.2500000
[3,] 2.333333 0.6666667 0.1111111
> X~Y
X ~ Y
> X %*% Y
     [,1] [,2] [,3]
[1,]   90   54   18
[2,]  114   69   24
[3,]  138   84   30
> t
[1] -1.2
> t(X)
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
> t(Y)
     [,1] [,2] [,3]
[1,]    9    8    7
[2,]    6    5    4
[3,]    3    2    1
> t(X)X
Error: unexpected symbol in "t(X)X"
> t(X)*X
     [,1] [,2] [,3]
[1,]    1    8   21
[2,]    8   25   48
[3,]   21   48   81
> diag(1)
     [,1]
[1,]    1
> diag(2)
     [,1] [,2]
[1,]    1    0
[2,]    0    1
> diag(3)
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
> diag(4)
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    0
[2,]    0    1    0    0
[3,]    0    0    1    0
[4,]    0    0    0    1
> diag(9)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
 [1,]    1    0    0    0    0    0    0
 [2,]    0    1    0    0    0    0    0
 [3,]    0    0    1    0    0    0    0
 [4,]    0    0    0    1    0    0    0
 [5,]    0    0    0    0    1    0    0
 [6,]    0    0    0    0    0    1    0
 [7,]    0    0    0    0    0    0    1
 [8,]    0    0    0    0    0    0    0
 [9,]    0    0    0    0    0    0    0
      [,8] [,9]
 [1,]    0    0
 [2,]    0    0
 [3,]    0    0
 [4,]    0    0
 [5,]    0    0
 [6,]    0    0
 [7,]    0    0
 [8,]    1    0
 [9,]    0    1
> diag(1:5)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    0
[2,]    0    2    0    0    0
[3,]    0    0    3    0    0
[4,]    0    0    0    4    0
[5,]    0    0    0    0    5
> x = cars$speed
> y = cars$dist
> Sxy = sum((x - mean(x)) * (y - mean(y)))
> Sxx = sum((x - mean(x)) ^ 2)
> Syy = sum((y - mean(y)) ^ 2)
> c(Sxy, Sxx, Syy)
[1]  5387.40  1370.00 32538.98
> beta_1_hat = Sxy / Sxx
> beta_0_hat = mean(y) - beta_1_hat * mean(x)
> c(beta_0_hat, beta_1_hat)
[1] -17.579095   3.932409

#creat vectors

> #(0.1^3 0.2^1,0.1^6 0.2^4.....,0.1^36 0.2^34 ) > (0.1^seq(3,36,by=3))*(0.2^seq(1,34,by=3)) [1] 2.000000e-04 1.600000e-09 1.280000e-14 [4] 1.024000e-19 8.192000e-25 6.553600e-30 [7] 5.242880e-35 4.194304e-40 3.355443e-45 [10] 2.684355e-50 2.147484e-55 1.717987e-60 > #(2,2^2/2,2^3/3,......,2^25/25) > (2^(1:25))/(1:25) [1] 2.000000e+00 2.000000e+00 2.666667e+00 [4] 4.000000e+00 6.400000e+00 1.066667e+01 [7] 1.828571e+01 3.200000e+01 5.688889e+01 [10] 1.024000e+02 1.861818e+02 3.413333e+02 [13] 6.301538e+02 1.170286e+03 2.184533e+03 [16] 4.096000e+03 7.710118e+03 1.456356e+04 [19] 2.759411e+04 5.242880e+04 9.986438e+04 [22] 1.906502e+05 3.647221e+05 6.990507e+05 [25] 1.342177e+06 > #sum > # > #(i^3+4i^2) where i=10:100 > mohi<-10:100 > sum(mohi^3+4*mohi^2) [1] 26852735 > rj<-1:25 > sum((2^rj)/rj+3*rj/(rj^2)) [1] 2807618 > #Function paste to create > #("label 1","label 2".......,"label 30") > paste("label",1:30) [1] "label 1" "label 2" "label 3" "label 4" [5] "label 5" "label 6" "label 7" "label 8" [9] "label 9" "label 10" "label 11" "label 12" [13] "label 13" "label 14" "label 15" "label 16" [17] "label 17" "label 18" "label 19" "label 20" [21] "label 21" "label 22" "label 23" "label 24" [25] "label 25" "label 26" "label 27" "label 28" [29] "label 29" "label 30" > #("fn1","fn2",....,"fn30") > paste("fn",1:30,sep="") [1] "fn1" "fn2" "fn3" "fn4" "fn5" "fn6" [7] "fn7" "fn8" "fn9" "fn10" "fn11" "fn12" [13] "fn13" "fn14" "fn15" "fn16" "fn17" "fn18" [19] "fn19" "fn20" "fn21" "fn22" "fn23" "fn24" [25] "fn25" "fn26" "fn27" "fn28" "fn29" "fn30"
Reactions

Post a Comment

0 Comments