forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
144 lines (144 loc) · 5.48 KB
/
.Rhistory
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
add2 <- function(x,y){
x + y
}
add2(5,3)
above <- function(x){
use <- x > n
x[use]
}
x <- 1:20
above(x,10)
above <- function(x,n){
use <- x > n
x[use]
}
above(x,10)
above <- function(x,n = 10){
use <- x > n
x[use]
}
above(x)
above(x,3)
x <- pollutantmean("2","6")
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
}
x <- pollutantmean("2","6")
x
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
}
x <- pollutantmean("2","6")
x <- pollutantmean("C:/coursera/Data Science/R Programming/Week 2/programming assignment one/rprog_data_specdata/specdata","6")
x
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
pollutant
}
x <- pollutantmean("C:/coursera/Data Science/R Programming/Week 2/programming assignment one/rprog_data_specdata/specdata","nitrate")
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
for (i in seq_along(files_full)) {
tmp[[i]] <- read.csv(files_full[[i]])
}
str(tmp)
}
x <- pollutantmean("C:/coursera/Data Science/R Programming/Week 2/programming assignment one/rprog_data_specdata/specdata","nitrate")
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
for (i in seq_along(files_list)) {
tmp[[i]] <- read.csv(files_list[[i]])
}
str(tmp)
}
x <- pollutantmean("C:/coursera/Data Science/R Programming/Week 2/programming assignment one/rprog_data_specdata/specdata","nitrate")
pollutantmean <- function(directory, pollutant, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'pollutant' is a character vector of length 1 indicating
## the name of the pollutant for which we will calculate the
## mean; either "sulfate" or "nitrate".
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return the mean of the pollutant across all monitors list
## in the 'id' vector (ignoring NA values)
## NOTE: Do not round the result!
files_list <- list.files(directory, full.names=TRUE) #creates a list of files
tmp <- vector(mode = "list", length = length(files_list))
for (i in seq_along(files_list)) {
tmp[[i]] <- read.csv(files_list[[i]])
}
str(tmp)
}
x <- pollutantmean("C:/coursera/Data Science/R Programming/Week 2/programming assignment one/rprog_data_specdata/specdata","nitrate")
library(datasets)
data(mtcars)
tapply(mtcars$mpg, mtcars$cyl, mean)
tapply(mtcars$mpg,mean)
tapply(mtcars$mpg, mtcars$cyl, mean)
26.66364 - 15.1
mean(mtcars$mpg, mtcars$cyl)
sapply(split(mtcars$mpg, mtcars$cyl), mean)
tapply(mtcars$cyl, mtcars$mpg, mean)
mean(mtcars$mpg, mtcars$cyl)
sapply(split(mtcars$mpg, mtcars$cyl), mean)
apply(mtcars, 2, mean)
head(mtcars)
abs(mean(mtcars[mtcars$cyl==4,]$hp) - mean(mtcars[mtcars$cyl==8,]$hp))
setwd("C:/coursera/Data Science/R Programming/Week 3/Programming assignment 2/ProgrammingAssignment2")
source("cacheMatrix.R")
x <- matrix(c(10,20,30,40), nrow=2, ncol=2) # create a matrix
x
m = makeCacheMatrix(x) # solve the matrix
m$get()
cacheSolve(m)
cacheSolve(m)