logo

R Programming Examples for Beginners

5 Pages2772 Words55 Views
   

Added on  2019-10-18

About This Document

This article provides hands-on examples for beginners to learn R programming. It covers basic operations, data frames, graphics, and more. The examples are explained step-by-step with code snippets and output. The article also mentions the solved assignments, essays, and dissertations available on Desklib for various courses and universities.

R Programming Examples for Beginners

   Added on 2019-10-18

ShareRelated Documents
1Hands-onExample 11+1Example 212 * (10 + 1)Example 3# Scientific notation3.5E03 + 4E-01Example 4sin(pi/2)Example 5abs(-10)Example 61001/0Example 7sqrt(225)Example 815^2Example 9floor(3.1415)Example 10p=5q=6p+qExample 11x <- 5y <- 2 * xx+yExample 12x*yExample 13y/xExample 14(x*y)/xExample 15message(x)Example 16x <- "Hello world"message(x)Example 17nums1 <- c(1,4,2,8,11,100,8)Example 19mean(nums1)Example 20sd(nums1)Example 21length(nums1)Example 22rev(nums1)Example 23cumsum(nums1)Example 24vec1 <- c(1,2,3,4,5)vec2 <- c(11,12,13,14,15)vec1 + 10Example 25vec1^2Example 26vec1 * vec2Example 27vec1 / vec2Example 28vec2 - vec1Example 29vec1 + vec2Example 30sum(vec1) + sum(vec2)Example 31mean(vec1^2)Example 32mean(vec1)^2Example 33sd(vec1 - 1.2)Example 34sd(vec1) - 1.2Example 35mean(log(vec2))Example 36log(mean(vec2))Example 37min(sqrt(vec1 + vec2))Example 39sum((vec1 - mean(vec1))^2) / (length(vec1) - 1)Example 40words <- c("pet","elk","star","apple","the letter r")Example 41sort(words)Example 42nchar(words)Example 43mat1 <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3)Example 44mat2 <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow=TRUE)Example 45sum(mat1)Example 46mean(mat1)Example 47sd(mat1)Example 48length(mat1)Example 49mat1 + 10Example 50mat2 * 10Example 51mat1 * mat2Example 52diag(mat1)Example 53rowSums(mat1)Example 54colSums(mat1)Example 55 t(mat1)Example 56 a <- c(1,2,3)b <- c(4,5,6)c(a,b)Example 571:10
R Programming Examples for Beginners_1
2Example 18sum(nums1)Example 38sum((vec1 - mean(vec1))^2)Example 58 5:-5 Example 59 seq(from=10,to=100,by=10)Example 60 seq(from=23, by=2, length=12)Example 61 rep(2, times = 10)Example 62 rep(c(4,5), each=3)Example 63 rep("a", times = 3)Example 64 rep(c("E. tereticornis","E. saligna"), each=3)Example 65 runif(10)Example 66 runif(5, 100, 1000)Example 67 numbers <- 1:15sample(numbers, size=20, replace=TRUE)Example 68 ls()Example 69 rm(nums1, nums2)Example 70 rm(list=ls())Example 71 setwd("C:/myR")Example 72 getwd()Example 73 dir()Example 74 dir("c:/work/projects/data/")Example 75 dir("data")Example 76 dir(pattern="[.]csv", Example 77 setwd("C:/projects/data")Example 78 rm(list=ls())Example 79 install.packages("gplots")Example 80library(gplots)Example 81 library(help=gplots)Example 82 ?ANOVAExample 86allom<-read.csv("Allometry.csv")Example 87allom<-read.csv("c:/projects/data/Allometry.csv")Example 88allom<-read.csv("data/Allometry.csv")Example 89head(allom)Example 90tail(allom)Example 91allomsmall<-read.csv("Allometry.csv",skip=10,nrows=5,header=FALSE)Example 92read.table(header=TRUE,text="a b 1 2 3 4")Example 93vec1<-c(9,10,1,2,45)vec2<-1:5data.frame(x=vec1,y=vec2)Example 94allom<-read.csv("Allometry.csv")Example 95head(allom)Example 96Example 97round(allom$diameter,1)Example 98allom$diameterInch<-allom$diameter/2.54Example 95allom$volindex<-with(allom, diameter^2*height)Example 100allom$volindex<-allom$diameter^2*allom$heightExample 101head(allom)Example 102summary(allom)Example 103nrow(allom)Example 104ncol(allom)Example 105names(allom)Example 106names(allom) <- c("spec","diam","ht","leafarea","branchm")Example 107names(allom)[2] <- "Diam"Example 108names(allom)[1:2] <- c("SP","D")Example 109nums1 <- c(1,4,2,8,11,100,8)nums2 <- c(3.3,8.1,2.5,9.8,21.2,13.8,0.9)Example 110nums1[1]Example 111nums1[5]Example 112 nelements <- length(nums1)nums1[nelements]Example 113nums1[1:3]Example 114
R Programming Examples for Beginners_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
bootstrap-and-jackknife Solutions 2022
|10
|1959
|18

Stock Price Simulation and Option Pricing
|7
|1286
|142

Real World Analytics Question Answer 2022
|8
|1741
|11

Questions of Show that the Jeffrey’s prior
|8
|745
|17

Statistics Assignment
|11
|1203
|458

Correlation Analysis in Business Analytics
|5
|893
|85