> getwd() [1] "C:/Users/Owner/Documents" > getwd() [1] "C:/Users/Owner/Documents" > ?cd No documentation for ‘cd’ in specified packages and libraries: you could try ‘??cd’ > ?setwd > setwd("C:/Users/Owner/Desktop") > getwd() [1] "C:/Users/Owner/Desktop" > ?read.csv > t <- read.csv("train.csv") > View(t) > summary(t) survived pclass Min. :0.0000 Min. :1.000 1st Qu.:0.0000 1st Qu.:2.000 Median :0.0000 Median :3.000 Mean :0.3838 Mean :2.309 3rd Qu.:1.0000 3rd Qu.:3.000 Max. :1.0000 Max. :3.000 name sex age Abbing, Mr. Anthony : 1 female:314 Min. : 0.42 Abbott, Mr. Rossmore Edward : 1 male :577 1st Qu.:20.12 Abbott, Mrs. Stanton (Rosa Hunt) : 1 Median :28.00 Abelson, Mr. Samuel : 1 Mean :29.70 Abelson, Mrs. Samuel (Hannah Wizosky): 1 3rd Qu.:38.00 Adahl, Mr. Mauritz Nils Martin : 1 Max. :80.00 (Other) :885 NA's :177 sibsp parch ticket fare Min. :0.000 Min. :0.0000 1601 : 7 Min. : 0.00 1st Qu.:0.000 1st Qu.:0.0000 347082 : 7 1st Qu.: 7.91 Median :0.000 Median :0.0000 CA. 2343: 7 Median : 14.45 Mean :0.523 Mean :0.3816 3101295 : 6 Mean : 32.20 3rd Qu.:1.000 3rd Qu.:0.0000 347088 : 6 3rd Qu.: 31.00 Max. :8.000 Max. :6.0000 CA 2144 : 6 Max. :512.33 (Other) :852 cabin embarked :687 : 2 B96 B98 : 4 C:168 C23 C25 C27: 4 Q: 77 G6 : 4 S:644 C22 C26 : 3 D : 3 (Other) :186 > predictor <- function(obs) { + return(0) + } > pr <- function(obs) { + return(0) + } > head(t) survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > t2 <- t[1:6,] > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > pr(t2[1,]) [1] 0 > t2[1,] survived pclass name sex age sibsp parch ticket 1 0 3 Braund, Mr. Owen Harris male 22 1 0 A/5 21171 fare cabin embarked 1 7.25 S > ?lapply > lapply(t2,pr) $survived [1] 0 $pclass [1] 0 $name [1] 0 $sex [1] 0 $age [1] 0 $sibsp [1] 0 $parch [1] 0 $ticket [1] 0 $fare [1] 0 $cabin [1] 0 $embarked [1] 0 > ?predict > predict function (object, ...) UseMethod("predict") > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > t2$sex [1] male female female female male male Levels: female male > t2[1,] survived pclass name sex age sibsp parch ticket 1 0 3 Braund, Mr. Owen Harris male 22 1 0 A/5 21171 fare cabin embarked 1 7.25 S > pr <- function(obs) { + if (obs$sex == "female") { + return(1) + } else { + return(0) + } + } > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > pr( t2[1,]) [1] 0 > pr( t2[2,]) [1] 1 > # full data-frame prediction... > df_pr(FUN,df) { Error: unexpected '{' in "df_pr(FUN,df) {" > L <- length(df) > print(L) [1] 1 > return(42) Error: no function to return from, jumping to top level > } Error: unexpected '}' in "}" > # full data-frame prediction... > df_pr <- function(FUN,df) { + L <- length(df) + print(L) + return(42) + } > df_pr(pr,t2) [1] 11 [1] 42 > length(t2) [1] 11 > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > str(t2) 'data.frame': 6 obs. of 11 variables: $ survived: int 0 1 1 1 0 0 $ pclass : int 3 1 3 1 3 3 $ name : Factor w/ 891 levels "Abbing, Mr. Anthony",..: 109 191 358 277 16 559 $ sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 $ age : num 22 38 26 35 35 NA $ sibsp : int 1 1 0 1 0 0 $ parch : int 0 0 0 0 0 0 $ ticket : Factor w/ 681 levels "110152","110413",..: 524 597 670 50 473 276 $ fare : num 7.25 71.28 7.92 53.1 8.05 ... $ cabin : Factor w/ 148 levels "","A10","A14",..: 1 83 1 57 1 1 $ embarked: Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 > nobs function (object, ...) UseMethod("nobs") > nobs(t2) Error in nobs.default(t2) : no 'nobs' method is available > ?nobs > ??nobs > ?nrows No documentation for ‘nrows’ in specified packages and libraries: you could try ‘??nrows’ > ??rows > length(t2[1]) [1] 1 > length(t2[[1]]) [1] 6 > ?concatenate No documentation for ‘concatenate’ in specified packages and libraries: you could try ‘??concatenate’ > cat("hi", 42) hi 42 > # full data-frame prediction... > df_pr <- function(FUN,df) { + NUM_ROWS <- length(df[[1]]) + cat("NUM_ROWS is", NUM_ROWS) + } > df_pr(t2) Error in df_pr(t2) : argument "df" is missing, with no default > df_pr(pr,t2) NUM_ROWS is 6 > ?nrow > nrow(t2) [1] 6 > ?vector > vector(mode="numeric",length=3) [1] 0 0 0 > # full data-frame prediction... > df_pr <- function(FUN,df) { + NUM_ROWS <- nrow(df) + cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + for (row in 1:NUM_ROWS) { + next_prediction = pr(df[row,]) + predictions[row] = next_prediction + } + return(predictions) + } > df_pr(pr,t2) NUM_ROWS is 6[1] 0 1 1 1 0 0 > # full data-frame prediction... > df_pr <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + for (row in 1:NUM_ROWS) { + next_prediction = pr(df[row,]) + predictions[row] = next_prediction + } + return(predictions) + } > x <- df_pr(pr,t2) > x [1] 0 1 1 1 0 0 > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > x [1] 0 1 1 1 0 0 > t2[1] survived 1 0 2 1 3 1 4 1 5 0 6 0 > t2[[1]] [1] 0 1 1 1 0 0 > x - t2[[1]] [1] 0 0 0 0 0 0 > sum(as.numeric(x == t2[[1]])) [1] 6 > sum(x == t2[[1]]) [1] 6 > y <- x > y[2] [1] 1 > y[2] <- 0 > y [1] 0 0 1 1 0 0 > x [1] 0 1 1 1 0 0 > t2[t2$survived!=y] pclass ticket 1 3 A/5 21171 2 1 PC 17599 3 3 STON/O2. 3101282 4 1 113803 5 3 373450 6 3 330877 > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > t2$survived [1] 0 1 1 1 0 0 > t2$survived!=y [1] FALSE TRUE FALSE FALSE FALSE FALSE > t2[t2$survived!=y,] survived pclass name 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) sex age sibsp parch ticket fare cabin embarked 2 female 38 1 0 PC 17599 71.2833 C85 C > t <- read.csv("train742.csv") > View(t) > View(t) > ?scan > mhall <- function() { + cat("Enter a number:") + user = scan(n=1) + cat("You entered",user) + } > mhall() Enter a number: 1: 45 Read 1 item You entered 45 > ?runif > ?sample > sample(seq(3),1) [1] 1 > replicate( 10, sample(seq(3),1)) [1] 3 1 3 1 3 2 3 1 3 2 > save.image("C:/Users/Owner/Desktop/wksp1.Rwk.RData") > sample(seq(3),1) [1] 2 > replicate( 10, sample(seq(3),1)) [1] 1 3 1 2 3 3 2 2 3 2 > } Error: unexpected '}' in "}" > source('C:/Users/Owner/Desktop/titanic.R', echo=TRUE) Error in source("C:/Users/Owner/Desktop/titanic.R", echo = TRUE) : C:/Users/Owner/Desktop/titanic.R:55:1: unexpected '<' 54: 55: < ^ > source('C:/Users/Owner/Desktop/titanic.R', echo=TRUE) > # Titanic problem starter file... > # Be sure to comment each function using # or " " > > " + Here is an example of multi-line quote-based 'com ..." ... [TRUNCATED] [1] "\n Here is an example of multi-line quote-based 'comments' ...\n\n pr0(obs) takes in one observation (obs)\n and outputs whether or not that passenger would have\n survived by our model...\n\n In the case of pr0, the prediction is that every\n passenger perishes (0)\n" > pr0 <- function(obs) { + return(0) + } > # Here is an example of #-style (single-line) comments > # > # pr1(obs) is a function that takes in one observation (obs) > # and outputs whether or .... [TRUNCATED] > " + df_pr(FUN,df) takes in + FUN: a function that predicts for one observation, such as + pr0 or pr1 + df: a dataframe with po ..." ... [TRUNCATED] [1] "\n df_pr(FUN,df) takes in\n FUN: a function that predicts for one observation, such as\n pr0 or pr1\n df: a dataframe with possible many observations to test\n\n df_pr returns a vector of predictions, one per row in the\n dataframe df\n" > df_pr <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + .... [TRUNCATED] > pr0(42) [1] 0 > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > source('C:/Users/Owner/Desktop/titanic.R', echo=TRUE) > # Titanic problem starter file... > # Be sure to comment each function using # or " " > > " + Here is an example of multi-line quote-based 'com ..." ... [TRUNCATED] [1] "\n Here is an example of multi-line quote-based 'comments' ...\n\n pr0(obs) takes in one observation (obs)\n and outputs whether or not that passenger would have\n survived by our model...\n\n In the case of pr0, the prediction is that every\n passenger perishes (0)\n" > pr0 <- function(obs) { + return(0) + } > # Here is an example of #-style (single-line) comments > # > # pr1(obs) is a function that takes in one observation (obs) > # and outputs whether or .... [TRUNCATED] > " + pr_df(FUN,df) takes in + FUN: a function that predicts for one observation, such as + pr0 or pr1 + df: a dataframe with po ..." ... [TRUNCATED] [1] "\n pr_df(FUN,df) takes in\n FUN: a function that predicts for one observation, such as\n pr0 or pr1\n df: a dataframe with possible many observations to test\n\n pr_df returns a vector of predictions, one per row in the\n dataframe df\n" > pr_df <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + .... [TRUNCATED] > t2 survived pclass name 1 0 3 Braund, Mr. Owen Harris 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) 3 1 3 Heikkinen, Miss. Laina 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 5 0 3 Allen, Mr. William Henry 6 0 3 Moran, Mr. James sex age sibsp parch ticket fare cabin embarked 1 male 22 1 0 A/5 21171 7.2500 S 2 female 38 1 0 PC 17599 71.2833 C85 C 3 female 26 0 0 STON/O2. 3101282 7.9250 S 4 female 35 1 0 113803 53.1000 C123 S 5 male 35 0 0 373450 8.0500 S 6 male NA 0 0 330877 8.4583 Q > pr_df(pr0,t2) [1] 0 1 1 1 0 0 > sum(t2[t2$survived == pr_df(pr0,t2)]) Error in FUN(X[[1L]], ...) : only defined on a data frame with all numeric variables > t2$survived [1] 0 1 1 1 0 0 > t2$survived == pr_df(pr0,t2) [1] TRUE TRUE TRUE TRUE TRUE TRUE > sum(t2$survived == pr_df(pr0,t2)) [1] 6 > print("Hi") [1] "Hi" > x <- 42 > print("Hi", x) Error in print.default("Hi", x) : invalid 'digits' argument > cat("Hi",x) Hi 42 > ?cat > cat("Hi",x) Hi 42 > View(sp) > sp V1 1 4779736 2 710231 3 6392017 4 2915918 5 37253956 6 5029196 7 3574097 8 897934 9 601723 10 18801310 11 9687653 12 1360301 13 1567582 14 12830632 15 6483802 16 3046355 17 2853118 18 4339367 19 4533372 20 1328361 21 5773552 22 6547629 23 9883640 24 5303925 25 2967297 26 5988927 27 989415 28 1826341 29 2700551 30 1316470 31 8791894 32 2059179 33 19378102 34 9535483 35 672591 36 11536504 37 3751351 38 3831074 39 12702379 40 1052567 41 4625364 42 814180 43 6346105 44 25145561 45 2763885 46 625741 47 8001024 48 6724540 49 1852994 50 5686986 51 563626 > ?read.csv > s <- read.csv("states.csv") > View(s) > View(sp) > View(s) > summary(s) State Pop .Alabama : 1 Min. : 563626 .Alaska : 1 1st Qu.: 1696962 .Arizona : 1 Median : 4339367 .Arkansas : 1 Mean : 6053834 .California: 1 3rd Qu.: 6636084 .Colorado : 1 Max. :37253956 (Other) :45 > hist(sp) Error in hist.default(sp) : 'x' must be numeric > sp V1 1 4779736 2 710231 3 6392017 4 2915918 5 37253956 6 5029196 7 3574097 8 897934 9 601723 10 18801310 11 9687653 12 1360301 13 1567582 14 12830632 15 6483802 16 3046355 17 2853118 18 4339367 19 4533372 20 1328361 21 5773552 22 6547629 23 9883640 24 5303925 25 2967297 26 5988927 27 989415 28 1826341 29 2700551 30 1316470 31 8791894 32 2059179 33 19378102 34 9535483 35 672591 36 11536504 37 3751351 38 3831074 39 12702379 40 1052567 41 4625364 42 814180 43 6346105 44 25145561 45 2763885 46 625741 47 8001024 48 6724540 49 1852994 50 5686986 51 563626 > sp <- s$pop > mode(sp) [1] "NULL" > hist(sp) Error in hist.default(sp) : 'x' must be numeric > sp <- as.numeric(sp) > hist(sp) Error in hist.default(sp) : invalid number of 'breaks' > sp <- s$Pop > sp [1] 4779736 710231 6392017 2915918 37253956 [6] 5029196 3574097 897934 601723 18801310 [11] 9687653 1360301 1567582 12830632 6483802 [16] 3046355 2853118 4339367 4533372 1328361 [21] 5773552 6547629 9883640 5303925 2967297 [26] 5988927 989415 1826341 2700551 1316470 [31] 8791894 2059179 19378102 9535483 672591 [36] 11536504 3751351 3831074 12702379 1052567 [41] 4625364 814180 6346105 25145561 2763885 [46] 625741 8001024 6724540 1852994 5686986 [51] 563626 > mode(sp) [1] "numeric" > hist(sp) > hist(sp,breaks=20) > ?quantile > quantile( sp, c(.5,.95)) 50% 95% 4339367 19089706 > quantile( sp, c(.05,.95)) 5% 95% 649166 19089706 > mean(sp) [1] 6053834 > sd(sp) [1] 6823984 > 1:10 [1] 1 2 3 4 5 6 7 8 9 10 > sample( 1:10, 3 ) [1] 4 9 1 > sample( sp, 16 ) [1] 18801310 12830632 1316470 672591 5988927 [6] 9883640 19378102 6724540 12702379 563626 [11] 5029196 2700551 11536504 1852994 9535483 [16] 1052567 > samp <- sample( sp, 16 ) > mean(samp) [1] 3887659 > man(sp) Error: could not find function "man" > mean(sp) [1] 6053834 > samp <- sample( sp, 16 ) ; mean(samp) [1] 6131865 > samp <- sample( sp, 16 ) ; mean(samp) [1] 4157934 > samp <- sample( sp, 16 ) ; mean(samp) [1] 3573474 > samp <- sample( sp, 16 ) ; mean(samp) [1] 4802867 > samp <- sample( sp, 16 ) ; mean(samp) [1] 6268459 > 42 ; 43 [1] 42 [1] 43 > sampdist <- replicate( 1000 , mean(sample( sp, 16 )) ) > length(sampdist) [1] 1000 > summary(sampdist) Min. 1st Qu. Median Mean 3rd Qu. Max. 2954000 5029000 6038000 6096000 7073000 10530000 > mean(sp) [1] 6053834 > hist(sampdist) > sampdist <- replicate( 10000 , mean(sample( sp, 16 )) ) > hist(sampdist) > unknown_mean = 4000000 > quantiles( sampdist, c(.05,.95)) Error: could not find function "quantiles" > quantile( sampdist, c(.05,.95)) 5% 95% 3869606 8505807 > mean(sp) [1] 6053834 > median(sp) [1] 4339367 > sort(sp) [1] 563626 601723 625741 672591 710231 [6] 814180 897934 989415 1052567 1316470 [11] 1328361 1360301 1567582 1826341 1852994 [16] 2059179 2700551 2763885 2853118 2915918 [21] 2967297 3046355 3574097 3751351 3831074 [26] 4339367 4533372 4625364 4779736 5029196 [31] 5303925 5686986 5773552 5988927 6346105 [36] 6392017 6483802 6547629 6724540 8001024 [41] 8791894 9535483 9687653 9883640 11536504 [46] 12702379 12830632 18801310 19378102 25145561 [51] 37253956 > sorted <- sort(sp) > sorted[26] [1] 4339367 > ?1which Error: unexpected symbol in "?1which" > ?1which Error: unexpected symbol in "?1which" > ?which > which(s$Pop==sorted[26]) [1] 18 > s[18] Error in `[.data.frame`(s, 18) : undefined columns selected > s[18,] State Pop 18 .Kentucky 4339367 > s[s$Pop == sorted[26]] Error in `[.data.frame`(s, s$Pop == sorted[26]) : undefined columns selected > s[s$Pop == sorted[26],] State Pop 18 .Kentucky 4339367 > s[s$Pop == sort(sp)[length(sp)/2],] State Pop 38 .Oregon 3831074 > length(sp)/2 [1] 25.5 > sort(sp)[25.5] [1] 3831074 > sort(sp)[25] [1] 3831074 > s[s$Pop == sort(sp)[(length(sp)+1)/2],] State Pop 18 .Kentucky 4339367 > which( c(1,2,3,2)==2 ) [1] 2 4 > which( c(7,8,9,8)==2 ) integer(0) > which( c(7,8,9,8)==8 ) [1] 2 4 > s[which( c(7,8,9,8)==8 ),] State Pop 2 .Alaska 710231 4 .Arkansas 2915918