This is your first R coding homework of this course. Please complete this homework in a RMarkdown document. You may either modify this document or start a new one. Knit this document to form an html file which you will then submit to Canvas. Please do not submit your .Rmd file. Make sure your html file is properly formatted (i.e., clear sections for each problem, tabbing, a table of contents). Make sure all code chunks are included in your homework under the corresponding problem. Any text answers required should be written under the coresopnding problem.
my_num that contains 6
numbers of your choicemy_num by 4my_char that contains 5
character strings of your choicemy_num and
my_char into a variable called both (hint: you can ues c()
to combine two variables together)my_num and
my_char?my_num and
my_char? Are the classes the same? If not, why?#a
my_num <- c(2, 4, 6, 8, 10, 12)
my_num
## [1] 2 4 6 8 10 12
#b
my_num_4 <- (my_num)*4
my_num_4
## [1] 8 16 24 32 40 48
#c
my_char <- c("apple", "banana", "cherry", "date", "elderberry")
my_char
## [1] "apple" "banana" "cherry" "date" "elderberry"
#d
both <- c(my_num,my_char)
both
## [1] "2" "4" "6" "8" "10"
## [6] "12" "apple" "banana" "cherry" "date"
## [11] "elderberry"
#e
length(my_num) # 6
## [1] 6
length(my_char) # 5
## [1] 5
#f
class(my_num) # numeric
## [1] "numeric"
class(my_char) # character
## [1] "character"
x <- c(1, 2, 3, 4, 5, 6)
x
## [1] 1 2 3 4 5 6
y <- c(10,20,30,40,50)
y
## [1] 10 20 30 40 50
(x)+(y) # you get, warning message In (x) + (y):longer object length is
## Warning in (x) + (y): longer object length is not a multiple of shorter object
## length
## [1] 11 22 33 44 55 16
# not a multiple of shorter object length
y <- c(y, 60)
y
## [1] 10 20 30 40 50 60
(x)+(y)
## [1] 11 22 33 44 55 66
(x)*(y)
## [1] 10 40 90 160 250 360
# R performs operations on vectors of the same length element-wise.
# In the case of addition, each element of x is added to the corresponding element of y.
# In the case of multiplication, each element of x is multiplied by the corresponding element of y.
first_ten that has the values 10
through 20 in it using the : operator.next_ten that has the values 21 through
30 in it using the seq() function.all_numbers by combining the previous
two vectors (hint: you can ues c() to combine two vectors together)eleventh that contains the 11th
element in all_numberssome_numbers that contains the 2nd
through the 5th elements of all_numberssome_numbers_2 that contains everything
except the 1st, 14th, and 23rd element of all_numbersfirst_ten <- 10:20
first_ten
## [1] 10 11 12 13 14 15 16 17 18 19 20
next_ten <- seq(from=21, to = 30)
next_ten
## [1] 21 22 23 24 25 26 27 28 29 30
all_numbers <- c(first_ten, next_ten)
all_numbers
## [1] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
eleventh <- all_numbers [11]
eleventh
## [1] 20
some_numbers <- all_numbers [2:5]
some_numbers
## [1] 11 12 13 14
some_numbers_2 <- all_numbers [-c(1, 14, 23)]
some_numbers_2
## [1] 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28 29 30
phone_numbers that contains the numbers
8, 6, 7, 5, 3, 0, 9prefix that has the
first three elements of phone_numberssmall that has the
values of phone_numbers that are less than or equal to
5large that has the
values of phone_numbers that are strictly greater than
5phone_numbers that are larger
than 5 with the number 5phone_numbers with
the number 0phone_numbers <- c(8,6,7,5,3,0,9)
phone_numbers
## [1] 8 6 7 5 3 0 9
prefix <- phone_numbers [1:3]
prefix
## [1] 8 6 7
small <- phone_numbers [phone_numbers <= 5]
small
## [1] 5 3 0
large <- phone_numbers [phone_numbers >5]
large
## [1] 8 6 7 9
phone_numbers[phone_numbers > 5] <- 5
phone_numbers
## [1] 5 5 5 5 3 0 5
phone_numbers[seq_along(phone_numbers) %% 2 == 1] <- 0
phone_numbers
## [1] 0 5 0 5 0 0 0
phone_numbers <- c(8,6,7,5,3,0,9)
phone_numbers[which(phone_numbers == 3)] <- 0
phone_numbers[which(phone_numbers == 5)] <- 0
phone_numbers[which(phone_numbers == 7)] <- 0
phone_numbers[which(phone_numbers == 9)] <- 0
print(phone_numbers)
## [1] 8 6 0 0 0 0 0
Monuments.xlsx dataset and call the output
mon. Print out the first 5 observations of this data.getwd()
## [1] "C:/Users/samah/OneDrive/Desktop/HW#5"
library(readr)
## Warning: package 'readr' was built under R version 4.3.3
Monuments_file<-read_csv("Monuments file.csv")
## Rows: 84 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, neighborhood, policeDistrict, Location 1
## dbl (2): zipCode, councilDistrict
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(readr)
mon<- read_csv("Monuments file.csv")
## Rows: 84 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, neighborhood, policeDistrict, Location 1
## dbl (2): zipCode, councilDistrict
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(mon,5)
## # A tibble: 5 × 6
## name zipCode neighborhood councilDistrict policeDistrict `Location 1`
## <chr> <dbl> <chr> <dbl> <chr> <chr>
## 1 James Cardin… 21201 Downtown 11 CENTRAL "408 CHARLE…
## 2 The Battle M… 21202 Downtown 11 CENTRAL <NA>
## 3 Negro Heroes… 21202 Downtown 11 CENTRAL <NA>
## 4 Star Bangled… 21202 Downtown 11 CENTRAL "100 HOLLID…
## 5 Flame at the… 21202 Downtown 11 CENTRAL "50 MARKET …
nrow(mon)
## [1] 84
ncol(mon)
## [1] 6
colnames(mon)
## [1] "name" "zipCode" "neighborhood" "councilDistrict"
## [5] "policeDistrict" "Location 1"
library(readr)
write_csv(mon,"C:/Users/samah/OneDrive/Desktop/monuments new.csv")
kaggleCarAuction.csv using readr and name
the dataset “cars”. Make sure each variable in your dataset has an
appropriate type based on the values it contains using col_type. You
must specify data types for each variable in your data set to get full
credit (don’t just let readr guess for you). Hint: open your data in
excel first and look at all your variables!cars <- read_csv(file= "kaggleCarAuction.csv")
## Rows: 72983 Columns: 34
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (24): PurchDate, Auction, Make, Model, Trim, SubModel, Color, Transmissi...
## dbl (10): RefId, IsBadBuy, VehYear, VehicleAge, VehOdo, BYRNO, VNZIP1, VehBC...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
cars
## # A tibble: 72,983 × 34
## RefId IsBadBuy PurchDate Auction VehYear VehicleAge Make Model Trim
## <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 1 0 12/7/2009 ADESA 2006 3 MAZDA MAZDA3 i
## 2 2 0 12/7/2009 ADESA 2004 5 DODGE 1500 RA… ST
## 3 3 0 12/7/2009 ADESA 2005 4 DODGE STRATUS… SXT
## 4 4 0 12/7/2009 ADESA 2004 5 DODGE NEON SXT
## 5 5 0 12/7/2009 ADESA 2005 4 FORD FOCUS ZX3
## 6 6 0 12/7/2009 ADESA 2004 5 MITSUBISHI GALANT … ES
## 7 7 0 12/7/2009 ADESA 2004 5 KIA SPECTRA EX
## 8 8 0 12/7/2009 ADESA 2005 4 FORD TAURUS SE
## 9 9 0 12/7/2009 ADESA 2007 2 KIA SPECTRA EX
## 10 10 0 12/7/2009 ADESA 2007 2 FORD FIVE HU… SEL
## # ℹ 72,973 more rows
## # ℹ 25 more variables: SubModel <chr>, Color <chr>, Transmission <chr>,
## # WheelTypeID <chr>, WheelType <chr>, VehOdo <dbl>, Nationality <chr>,
## # Size <chr>, TopThreeAmericanName <chr>,
## # MMRAcquisitionAuctionAveragePrice <chr>,
## # MMRAcquisitionAuctionCleanPrice <chr>,
## # MMRAcquisitionRetailAveragePrice <chr>, …
spec(cars)
## cols(
## RefId = col_double(),
## IsBadBuy = col_double(),
## PurchDate = col_character(),
## Auction = col_character(),
## VehYear = col_double(),
## VehicleAge = col_double(),
## Make = col_character(),
## Model = col_character(),
## Trim = col_character(),
## SubModel = col_character(),
## Color = col_character(),
## Transmission = col_character(),
## WheelTypeID = col_character(),
## WheelType = col_character(),
## VehOdo = col_double(),
## Nationality = col_character(),
## Size = col_character(),
## TopThreeAmericanName = col_character(),
## MMRAcquisitionAuctionAveragePrice = col_character(),
## MMRAcquisitionAuctionCleanPrice = col_character(),
## MMRAcquisitionRetailAveragePrice = col_character(),
## MMRAcquisitonRetailCleanPrice = col_character(),
## MMRCurrentAuctionAveragePrice = col_character(),
## MMRCurrentAuctionCleanPrice = col_character(),
## MMRCurrentRetailAveragePrice = col_character(),
## MMRCurrentRetailCleanPrice = col_character(),
## PRIMEUNIT = col_character(),
## AUCGUART = col_character(),
## BYRNO = col_double(),
## VNZIP1 = col_double(),
## VNST = col_character(),
## VehBCost = col_double(),
## IsOnlineSale = col_double(),
## WarrantyCost = col_double()
## )
dim(cars) # [1] obs = 72983 var = 34
## [1] 72983 34
tail(cars, 5)
## # A tibble: 5 × 34
## RefId IsBadBuy PurchDate Auction VehYear VehicleAge Make Model Trim SubModel
## <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr>
## 1 73010 1 12/2/2009 ADESA 2001 8 MERC… SABLE GS 4D SEDA…
## 2 73011 0 12/2/2009 ADESA 2007 2 CHEV… MALI… LS 4D SEDA…
## 3 73012 0 12/2/2009 ADESA 2005 4 JEEP GRAN… Lar 4D WAGO…
## 4 73013 0 12/2/2009 ADESA 2006 3 CHEV… IMPA… LS 4D SEDA…
## 5 73014 0 12/2/2009 ADESA 2006 3 MAZDA MAZD… s 4D SEDA…
## # ℹ 24 more variables: Color <chr>, Transmission <chr>, WheelTypeID <chr>,
## # WheelType <chr>, VehOdo <dbl>, Nationality <chr>, Size <chr>,
## # TopThreeAmericanName <chr>, MMRAcquisitionAuctionAveragePrice <chr>,
## # MMRAcquisitionAuctionCleanPrice <chr>,
## # MMRAcquisitionRetailAveragePrice <chr>,
## # MMRAcquisitonRetailCleanPrice <chr>, MMRCurrentAuctionAveragePrice <chr>,
## # MMRCurrentAuctionCleanPrice <chr>, MMRCurrentRetailAveragePrice <chr>, …
whaledata.txt file using base R. Name the
output whale. Print the first 5 observations of this dataset. (hint:
Make sure you look at this file before importing).whaledatanamed.txt using base R. Name
this output whale_2. Explicitly specify the data types of each variable
in whaledatanamed.txt in your import call. Print the first
5 observations of this dataset. (hint: Make sure you look at this file
before importing).whale <- read.delim(file="whaledata.txt", header=FALSE)
whale
## V1 V2 V3 V4 V5 V6 V7 V8
## 1 May 1344 low 7 60.37 -4.18 520 415
## 2 May 1633 medium 13 60.38 -4.19 559 405
## 3 May 743 medium 12 60.54 -4.62 1006 88
## 4 May 1050 medium 10 60.29 -4.35 540 409
## 5 May 1764 medium 12 60.41 -5.20 1000 97
## 6 May 580 high 10 60.38 -5.22 1000 173
## 7 May 459 medium 5 60.40 -5.08 993 162
## 8 May 561 medium 8 60.41 -5.00 988 162
## 9 May 709 medium 11 60.44 -4.64 954 245
## 10 May 690 medium 12 60.43 -4.84 984 161
## 11 May 634 medium 9 60.43 -4.75 965 127
## 12 May 422 low 11 60.86 -1.53 120 23
## 13 May 1232 medium 11 61.29 -2.93 1195 217
## 14 May 1232 low 12 61.25 -2.76 1088 261
## 15 May 1451 low 12 61.42 -3.51 1259 109
## 16 May 1441 low 12 61.40 -3.41 1277 111
## 17 May 1566 medium 17 61.38 -3.32 1288 100
## 18 May 1578 low 11 61.52 -3.94 1200 152
## 19 May 1475 medium 7 61.53 -4.02 1171 198
## 20 May 1544 medium 5 61.60 -4.34 832 671
## 21 May 1707 medium 9 61.67 -4.65 400 226
## 22 May 234 medium 4 61.75 -5.07 255 111
## 23 May 1206 low 13 61.61 -6.33 195 133
## 24 May 1092 low 11 61.51 -4.16 1124 232
## 25 May 1134 low 12 61.55 -4.18 1076 306
## 26 May 1079 low 11 61.47 -4.16 1133 166
## 27 May 1232 medium 15 61.59 -4.18 1024 361
## 28 May 1024 low 10 61.39 -4.16 1105 118
## 29 May 1086 low 12 61.43 -4.15 1125 141
## 30 May 1341 low 18 61.64 -4.18 934 394
## 31 May 840 low 0 61.67 -4.18 869 361
## 32 May 1254 low 14 61.72 -4.18 757 361
## 33 May 1087 low 18 60.98 -4.26 1100 0
## 34 May 832 low 7 61.10 -4.20 1100 29
## 35 May 1030 low 11 61.34 -4.16 1100 78
## 36 May 935 low 10 61.14 -4.21 1100 29
## 37 May 1148 medium 21 60.92 -4.40 1100 49
## 38 May 945 low 10 61.19 -4.20 1100 7
## 39 May 816 low 14 60.64 -4.88 1000 102
## 40 May 663 low NA 60.67 -4.83 1016 114
## 41 May 605 medium 10 60.54 -4.96 1000 8
## 42 May 651 medium 11 60.52 -5.05 1000 33
## 43 May 754 medium 14 60.51 -5.14 1000 56
## 44 May 615 medium 8 60.58 -5.00 1000 54
## 45 May 647 medium 10 60.52 -5.14 1000 73
## 46 May 1216 high 17 61.99 -2.26 1593 120
## 47 May 905 high 7 61.94 -2.41 1601 118
## 48 May 1329 high 28 61.59 -3.06 1425 106
## 49 May 787 medium 13 61.33 -3.50 1204 134
## 50 May 803 medium 13 61.36 -3.46 1238 126
## 51 October 545 medium 5 61.29 -3.57 1178 130
## 52 October 1137 high 12 62.10 -2.01 1610 134
## 53 October 948 high 9 61.91 -2.48 1600 110
## 54 October 1041 high 9 62.07 -2.06 1600 123
## 55 October 1454 high 25 62.01 -2.18 1596 125
## 56 October 792 high 1 62.04 -2.12 1592 115
## 57 October 1096 high 10 62.07 -2.01 1584 124
## 58 October 787 high 8 61.62 -3.00 1455 103
## 59 October 1252 high 15 62.01 -2.00 1553 122
## 60 October 1076 medium 6 61.82 -2.00 1502 128
## 61 October 1140 medium 8 61.78 -2.00 1488 135
## 62 October 1419 medium 17 61.72 -2.01 1448 183
## 63 October 1272 medium 11 61.66 -2.02 1406 248
## 64 October 1071 medium 7 61.90 -2.01 1517 151
## 65 October 901 high 8 61.87 -2.58 1587 88
## 66 October 1335 medium 12 61.57 -2.01 1256 356
## 67 October 658 medium 7 61.42 -3.33 1300 104
## 68 October 790 medium 11 61.46 -3.28 1321 95
## 69 October 824 high 9 61.65 -2.96 1484 94
## 70 October 1365 medium 13 61.53 -2.00 1183 394
## 71 October 1506 medium 17 61.49 -2.00 1090 444
## 72 October 1342 medium 11 61.45 -2.00 1007 505
## 73 October 1164 high 19 61.78 -2.74 1549 63
## 74 October 1250 medium 7 61.41 -2.00 901 467
## 75 October 1512 low 16 61.36 -2.00 735 400
## 76 October 1238 medium 5 61.30 -1.99 647 288
## 77 October 521 low 9 60.44 -4.26 687 421
## 78 October 625 low 12 60.45 -4.30 765 397
## 79 October 1871 medium 18 60.83 -4.34 1100 22
## 80 October 1942 low 21 60.79 -4.33 1100 79
## 81 October 1592 medium 9 60.74 -4.33 1084 148
## 82 October 1539 medium 10 60.50 -4.35 905 326
## 83 October 1672 medium 14 60.56 -4.33 934 285
## 84 October 1854 medium 19 60.69 -4.33 1024 213
## 85 October 1579 low 12 60.45 -4.38 900 333
## 86 October 555 medium 18 60.92 -4.98 951 246
## 87 October 60 medium 0 60.92 -5.08 912 364
## 88 October 480 medium 16 60.92 -4.87 993 177
## 89 October 2158 medium 25 60.92 -4.77 1000 171
## 90 October 1583 medium 5 60.92 -4.65 1033 131
## 91 October 1754 low 12 60.92 -4.50 1100 100
## 92 October 1854 medium 15 60.92 -4.58 1054 105
## 93 October 652 medium 13 60.75 -4.53 1100 41
## 94 October 441 medium 6 60.75 -4.62 1100 41
## 95 October 775 medium 20 60.75 -4.99 946 210
## 96 October 506 medium 10 60.75 -4.89 1009 188
## 97 October 695 medium 16 60.75 -4.80 1057 135
## 98 October 519 medium 9 60.75 -4.69 1099 69
## 99 October 563 medium 6 60.58 -4.79 1000 46
## 100 October 659 medium 10 60.58 -4.70 1016 69
head(whale, 5)
## V1 V2 V3 V4 V5 V6 V7 V8
## 1 May 1344 low 7 60.37 -4.18 520 415
## 2 May 1633 medium 13 60.38 -4.19 559 405
## 3 May 743 medium 12 60.54 -4.62 1006 88
## 4 May 1050 medium 10 60.29 -4.35 540 409
## 5 May 1764 medium 12 60.41 -5.20 1000 97
whale_2 <- read.delim(file="whaledatanamed.txt", header=TRUE)
whale_2
## month time.at.station water.noise number.whales latitude longitude depth
## 1 May 1344 low 7 60.37 -4.18 520
## 2 May 1633 medium 13 60.38 -4.19 559
## 3 May 743 medium 12 60.54 -4.62 1006
## 4 May 1050 medium 10 60.29 -4.35 540
## 5 May 1764 medium 12 60.41 -5.20 1000
## 6 May 580 high 10 60.38 -5.22 1000
## 7 May 459 medium 5 60.40 -5.08 993
## 8 May 561 medium 8 60.41 -5.00 988
## 9 May 709 medium 11 60.44 -4.64 954
## 10 May 690 medium 12 60.43 -4.84 984
## 11 May 634 medium 9 60.43 -4.75 965
## 12 May 422 low 11 60.86 -1.53 120
## 13 May 1232 medium 11 61.29 -2.93 1195
## 14 May 1232 low 12 61.25 -2.76 1088
## 15 May 1451 low 12 61.42 -3.51 1259
## 16 May 1441 low 12 61.40 -3.41 1277
## 17 May 1566 medium 17 61.38 -3.32 1288
## 18 May 1578 low 11 61.52 -3.94 1200
## 19 May 1475 medium 7 61.53 -4.02 1171
## 20 May 1544 medium 5 61.60 -4.34 832
## 21 May 1707 medium 9 61.67 -4.65 400
## 22 May 234 medium 4 61.75 -5.07 255
## 23 May 1206 low 13 61.61 -6.33 195
## 24 May 1092 low 11 61.51 -4.16 1124
## 25 May 1134 low 12 61.55 -4.18 1076
## 26 May 1079 low 11 61.47 -4.16 1133
## 27 May 1232 medium 15 61.59 -4.18 1024
## 28 May 1024 low 10 61.39 -4.16 1105
## 29 May 1086 low 12 61.43 -4.15 1125
## 30 May 1341 low 18 61.64 -4.18 934
## 31 May 840 low 0 61.67 -4.18 869
## 32 May 1254 low 14 61.72 -4.18 757
## 33 May 1087 low 18 60.98 -4.26 1100
## 34 May 832 low 7 61.10 -4.20 1100
## 35 May 1030 low 11 61.34 -4.16 1100
## 36 May 935 low 10 61.14 -4.21 1100
## 37 May 1148 medium 21 60.92 -4.40 1100
## 38 May 945 low 10 61.19 -4.20 1100
## 39 May 816 low 14 60.64 -4.88 1000
## 40 May 663 low NA 60.67 -4.83 1016
## 41 May 605 medium 10 60.54 -4.96 1000
## 42 May 651 medium 11 60.52 -5.05 1000
## 43 May 754 medium 14 60.51 -5.14 1000
## 44 May 615 medium 8 60.58 -5.00 1000
## 45 May 647 medium 10 60.52 -5.14 1000
## 46 May 1216 high 17 61.99 -2.26 1593
## 47 May 905 high 7 61.94 -2.41 1601
## 48 May 1329 high 28 61.59 -3.06 1425
## 49 May 787 medium 13 61.33 -3.50 1204
## 50 May 803 medium 13 61.36 -3.46 1238
## 51 October 545 medium 5 61.29 -3.57 1178
## 52 October 1137 high 12 62.10 -2.01 1610
## 53 October 948 high 9 61.91 -2.48 1600
## 54 October 1041 high 9 62.07 -2.06 1600
## 55 October 1454 high 25 62.01 -2.18 1596
## 56 October 792 high 1 62.04 -2.12 1592
## 57 October 1096 high 10 62.07 -2.01 1584
## 58 October 787 high 8 61.62 -3.00 1455
## 59 October 1252 high 15 62.01 -2.00 1553
## 60 October 1076 medium 6 61.82 -2.00 1502
## 61 October 1140 medium 8 61.78 -2.00 1488
## 62 October 1419 medium 17 61.72 -2.01 1448
## 63 October 1272 medium 11 61.66 -2.02 1406
## 64 October 1071 medium 7 61.90 -2.01 1517
## 65 October 901 high 8 61.87 -2.58 1587
## 66 October 1335 medium 12 61.57 -2.01 1256
## 67 October 658 medium 7 61.42 -3.33 1300
## 68 October 790 medium 11 61.46 -3.28 1321
## 69 October 824 high 9 61.65 -2.96 1484
## 70 October 1365 medium 13 61.53 -2.00 1183
## 71 October 1506 medium 17 61.49 -2.00 1090
## 72 October 1342 medium 11 61.45 -2.00 1007
## 73 October 1164 high 19 61.78 -2.74 1549
## 74 October 1250 medium 7 61.41 -2.00 901
## 75 October 1512 low 16 61.36 -2.00 735
## 76 October 1238 medium 5 61.30 -1.99 647
## 77 October 521 low 9 60.44 -4.26 687
## 78 October 625 low 12 60.45 -4.30 765
## 79 October 1871 medium 18 60.83 -4.34 1100
## 80 October 1942 low 21 60.79 -4.33 1100
## 81 October 1592 medium 9 60.74 -4.33 1084
## 82 October 1539 medium 10 60.50 -4.35 905
## 83 October 1672 medium 14 60.56 -4.33 934
## 84 October 1854 medium 19 60.69 -4.33 1024
## 85 October 1579 low 12 60.45 -4.38 900
## 86 October 555 medium 18 60.92 -4.98 951
## 87 October 60 medium 0 60.92 -5.08 912
## 88 October 480 medium 16 60.92 -4.87 993
## 89 October 2158 medium 25 60.92 -4.77 1000
## 90 October 1583 medium 5 60.92 -4.65 1033
## 91 October 1754 low 12 60.92 -4.50 1100
## 92 October 1854 medium 15 60.92 -4.58 1054
## 93 October 652 medium 13 60.75 -4.53 1100
## 94 October 441 medium 6 60.75 -4.62 1100
## 95 October 775 medium 20 60.75 -4.99 946
## 96 October 506 medium 10 60.75 -4.89 1009
## 97 October 695 medium 16 60.75 -4.80 1057
## 98 October 519 medium 9 60.75 -4.69 1099
## 99 October 563 medium 6 60.58 -4.79 1000
## 100 October 659 medium 10 60.58 -4.70 1016
## gradient
## 1 415
## 2 405
## 3 88
## 4 409
## 5 97
## 6 173
## 7 162
## 8 162
## 9 245
## 10 161
## 11 127
## 12 23
## 13 217
## 14 261
## 15 109
## 16 111
## 17 100
## 18 152
## 19 198
## 20 671
## 21 226
## 22 111
## 23 133
## 24 232
## 25 306
## 26 166
## 27 361
## 28 118
## 29 141
## 30 394
## 31 361
## 32 361
## 33 0
## 34 29
## 35 78
## 36 29
## 37 49
## 38 7
## 39 102
## 40 114
## 41 8
## 42 33
## 43 56
## 44 54
## 45 73
## 46 120
## 47 118
## 48 106
## 49 134
## 50 126
## 51 130
## 52 134
## 53 110
## 54 123
## 55 125
## 56 115
## 57 124
## 58 103
## 59 122
## 60 128
## 61 135
## 62 183
## 63 248
## 64 151
## 65 88
## 66 356
## 67 104
## 68 95
## 69 94
## 70 394
## 71 444
## 72 505
## 73 63
## 74 467
## 75 400
## 76 288
## 77 421
## 78 397
## 79 22
## 80 79
## 81 148
## 82 326
## 83 285
## 84 213
## 85 333
## 86 246
## 87 364
## 88 177
## 89 171
## 90 131
## 91 100
## 92 105
## 93 41
## 94 41
## 95 210
## 96 188
## 97 135
## 98 69
## 99 46
## 100 69
class(whale_2)
## [1] "data.frame"
head(whale_2, 5)
## month time.at.station water.noise number.whales latitude longitude depth
## 1 May 1344 low 7 60.37 -4.18 520
## 2 May 1633 medium 13 60.38 -4.19 559
## 3 May 743 medium 12 60.54 -4.62 1006
## 4 May 1050 medium 10 60.29 -4.35 540
## 5 May 1764 medium 12 60.41 -5.20 1000
## gradient
## 1 415
## 2 405
## 3 88
## 4 409
## 5 97
library(readr)
write_delim(whale_2,"C:/Users/samah/OneDrive/Desktop/Whales_new.txt")
beoverunder.sas7bdat dataset into r. Print
out the first 5 observations.rscfp2019.dta dataset into r. Print out the
first 5 observations.africa.sav dataset into r. Print out the
first 5 observations.library(haven)
## Warning: package 'haven' was built under R version 4.3.3
library(haven)
beoverunder <-read_sas("beoverunder.sas7bdat")
beoverunder
## # A tibble: 455 × 6
## site plot year burn planttype ANPP
## <chr> <dbl> <dbl> <chr> <chr> <dbl>
## 1 Dry site 1 2002 Frequent Nonpine 1.32
## 2 Dry site 1 2003 Frequent Nonpine 3.78
## 3 Dry site 1 2004 Frequent Nonpine 3.29
## 4 Dry site 1 2005 Frequent Nonpine 4.83
## 5 Dry site 1 2006 Frequent Nonpine 2.21
## 6 Dry site 1 2002 Frequent Pine 8.21
## 7 Dry site 1 2003 Frequent Pine 7.78
## 8 Dry site 1 2004 Frequent Pine 4.43
## 9 Dry site 1 2005 Frequent Pine 2.54
## 10 Dry site 1 2006 Frequent Pine 1.41
## # ℹ 445 more rows
head(beoverunder, 5)
## # A tibble: 5 × 6
## site plot year burn planttype ANPP
## <chr> <dbl> <dbl> <chr> <chr> <dbl>
## 1 Dry site 1 2002 Frequent Nonpine 1.32
## 2 Dry site 1 2003 Frequent Nonpine 3.78
## 3 Dry site 1 2004 Frequent Nonpine 3.29
## 4 Dry site 1 2005 Frequent Nonpine 4.83
## 5 Dry site 1 2006 Frequent Nonpine 2.21
rscfp2019 <- read_dta("rscfp2019.dta")
rscfp2019
## # A tibble: 28,885 × 351
## yy1 y1 wgt hhsex age agecl educ edcl married kids lf lifecl
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 11 6120. 2 75 6 12 4 2 0 1 5
## 2 1 12 4712. 2 75 6 12 4 2 0 1 5
## 3 1 13 5145. 2 75 6 12 4 2 0 1 5
## 4 1 14 5298. 2 75 6 12 4 2 0 1 5
## 5 1 15 4762. 2 75 6 12 4 2 0 1 5
## 6 2 21 3790. 1 50 3 8 2 1 3 1 3
## 7 2 22 3799. 1 50 3 8 2 1 3 1 3
## 8 2 23 3799. 1 50 3 8 2 1 3 1 3
## 9 2 24 3788. 1 50 3 8 2 1 3 1 3
## 10 2 25 3793. 1 50 3 8 2 1 3 1 3
## # ℹ 28,875 more rows
## # ℹ 339 more variables: famstruct <dbl>, racecl <dbl>, racecl4 <dbl>,
## # race <dbl>, occat1 <dbl>, occat2 <dbl>, indcat <dbl>, foodhome <dbl>,
## # foodaway <dbl>, fooddelv <dbl>, rent <dbl>, income <dbl>, wageinc <dbl>,
## # bussefarminc <dbl>, intdivinc <dbl>, kginc <dbl>, ssretinc <dbl>,
## # transfothinc <dbl>, penacctwd <dbl>, norminc <dbl>, wsaved <dbl>,
## # saved <dbl>, savres1 <dbl>, savres2 <dbl>, savres3 <dbl>, savres4 <dbl>, …
#Print the first 5 observations
head(rscfp2019, 5)
## # A tibble: 5 × 351
## yy1 y1 wgt hhsex age agecl educ edcl married kids lf lifecl
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 11 6120. 2 75 6 12 4 2 0 1 5
## 2 1 12 4712. 2 75 6 12 4 2 0 1 5
## 3 1 13 5145. 2 75 6 12 4 2 0 1 5
## 4 1 14 5298. 2 75 6 12 4 2 0 1 5
## 5 1 15 4762. 2 75 6 12 4 2 0 1 5
## # ℹ 339 more variables: famstruct <dbl>, racecl <dbl>, racecl4 <dbl>,
## # race <dbl>, occat1 <dbl>, occat2 <dbl>, indcat <dbl>, foodhome <dbl>,
## # foodaway <dbl>, fooddelv <dbl>, rent <dbl>, income <dbl>, wageinc <dbl>,
## # bussefarminc <dbl>, intdivinc <dbl>, kginc <dbl>, ssretinc <dbl>,
## # transfothinc <dbl>, penacctwd <dbl>, norminc <dbl>, wsaved <dbl>,
## # saved <dbl>, savres1 <dbl>, savres2 <dbl>, savres3 <dbl>, savres4 <dbl>,
## # savres5 <dbl>, savres6 <dbl>, savres7 <dbl>, savres8 <dbl>, …
africa <- read_spss("africa.sav")
africa
## # A tibble: 17 × 3
## COUNTRY FERTRATE CONTRA
## <chr> <dbl> <dbl>
## 1 Benin 7.10 9
## 2 Botswana 5 33
## 3 Burundi 6.80 9
## 4 Cameroon 6.40 2
## 5 Cote_d 7.40 3
## 6 Ghana 6.40 13
## 7 Kenya 6.70 27
## 8 Lesotho 5.80 7
## 9 Liberia 6.60 7
## 10 Mali 6.70 5
## 11 Nigeria 6.20 6
## 12 Rwanda 8.5 10
## 13 Senegal 6.60 11
## 14 Sudan 5.90 6
## 15 Togo 6.20 34
## 16 Uganda 7.30 5
## 17 Zimbabwe 5.70 43
library(haven)
africa <- read_sav("africa.sav")
africa
## # A tibble: 17 × 3
## COUNTRY FERTRATE CONTRA
## <chr> <dbl> <dbl>
## 1 Benin 7.10 9
## 2 Botswana 5 33
## 3 Burundi 6.80 9
## 4 Cameroon 6.40 2
## 5 Cote_d 7.40 3
## 6 Ghana 6.40 13
## 7 Kenya 6.70 27
## 8 Lesotho 5.80 7
## 9 Liberia 6.60 7
## 10 Mali 6.70 5
## 11 Nigeria 6.20 6
## 12 Rwanda 8.5 10
## 13 Senegal 6.60 11
## 14 Sudan 5.90 6
## 15 Togo 6.20 34
## 16 Uganda 7.30 5
## 17 Zimbabwe 5.70 43
head(africa, 5)
## # A tibble: 5 × 3
## COUNTRY FERTRATE CONTRA
## <chr> <dbl> <dbl>
## 1 Benin 7.10 9
## 2 Botswana 5 33
## 3 Burundi 6.80 9
## 4 Cameroon 6.40 2
## 5 Cote_d 7.40 3