# Load necessary libraries
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.3 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readr)
library(ggplot2)
mpg<- read_delim("C:/Users/Jamil Shaikh/Desktop/heart1.csv", delim = ",",show_col_types = FALSE)
# Define the number of samples and the sample size (50% of the data)
num_samples <- 7
sample_size <- nrow(mpg) * 0.5
# Create a list to store the sample data frames
sample_data_frames <- list()
# Generate random samples
for (i in 1:num_samples) {
# Sample rows with replacement
sample_rows <- sample(nrow(mpg), sample_size, replace = TRUE)
# Create a data frame with sampled rows and columns 1-6
sample_df <- mpg[sample_rows, 1:6]
# Append the sample data frame to the list
sample_data_frames[[paste0("df_", i)]] <- sample_df
}
sample_data_frames[[1]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 62 1 0 120 267 0
## 2 56 1 1 120 236 0
## 3 47 1 2 130 253 0
## 4 74 0 1 120 269 0
## 5 68 0 2 120 211 0
## 6 60 0 3 150 240 0
## 7 35 1 1 122 192 0
## 8 60 0 3 150 240 0
## 9 46 1 1 101 197 1
## 10 44 1 2 120 226 0
## # ℹ 141 more rows
sample_data_frames[[2]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 65 1 0 110 248 0
## 2 41 1 0 110 172 0
## 3 62 0 2 130 263 0
## 4 45 0 1 112 160 0
## 5 44 1 1 120 220 0
## 6 54 1 2 120 258 0
## 7 52 1 1 134 201 0
## 8 53 1 0 142 226 0
## 9 51 1 2 125 245 1
## 10 64 1 0 145 212 0
## # ℹ 141 more rows
sample_data_frames[[3]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 51 1 0 140 261 0
## 2 57 1 0 140 192 0
## 3 59 1 0 138 271 0
## 4 54 1 0 140 239 0
## 5 50 1 0 144 200 0
## 6 48 1 0 122 222 0
## 7 56 1 2 130 256 1
## 8 43 1 0 115 303 0
## 9 60 1 0 125 258 0
## 10 67 1 2 152 212 0
## # ℹ 141 more rows
sample_data_frames[[4]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 61 1 0 120 260 0
## 2 65 0 0 150 225 0
## 3 64 1 0 128 263 0
## 4 57 1 0 110 335 0
## 5 64 0 0 130 303 0
## 6 59 1 3 134 204 0
## 7 38 1 3 120 231 0
## 8 61 1 0 138 166 0
## 9 57 0 0 120 354 0
## 10 58 1 0 146 218 0
## # ℹ 141 more rows
sample_data_frames[[5]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 64 1 0 120 246 0
## 2 63 0 2 135 252 0
## 3 56 1 1 130 221 0
## 4 51 1 2 94 227 0
## 5 46 0 0 138 243 0
## 6 61 1 0 138 166 0
## 7 63 1 0 130 330 1
## 8 42 1 2 130 180 0
## 9 46 0 1 105 204 0
## 10 54 1 0 110 239 0
## # ℹ 141 more rows
sample_data_frames[[6]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 60 0 3 150 240 0
## 2 42 0 2 120 209 0
## 3 37 1 2 130 250 0
## 4 58 1 0 100 234 0
## 5 42 1 0 140 226 0
## 6 63 1 0 130 330 1
## 7 67 0 0 106 223 0
## 8 67 1 2 152 212 0
## 9 58 1 0 128 216 0
## 10 55 0 0 180 327 0
## # ℹ 141 more rows
sample_data_frames[[7]]
## # A tibble: 151 × 6
## age sex cp trestbps chol fbs
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 58 1 0 125 300 0
## 2 40 1 0 152 223 0
## 3 46 0 2 142 177 0
## 4 51 0 0 130 305 0
## 5 70 1 1 156 245 0
## 6 45 0 0 138 236 0
## 7 54 1 0 120 188 0
## 8 63 0 0 108 269 0
## 9 45 1 1 128 308 0
## 10 54 0 2 160 201 0
## # ℹ 141 more rows