myawesomepkg 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ ✅ Step 1: Load dplyr
2
+ r
3
+ Copy
4
+ Edit
5
+ library(dplyr)
6
+ 🔹 Sample Data
7
+ r
8
+ Copy
9
+ Edit
10
+ employees <- data.frame(
11
+ emp_id = c(1, 2, 3, 4, 5),
12
+ name = c("John", "Emma", "Raj", "Sara", "Mike"),
13
+ dept_id = c(10, 20, 10, 30, 20)
14
+ )
15
+
16
+ departments <- data.frame(
17
+ dept_id = c(10, 20, 30),
18
+ dept_name = c("HR", "Finance", "IT")
19
+ )
20
+ 🔹 1. Filtering Rows
21
+ r
22
+ Copy
23
+ Edit
24
+ # Filter employees from dept 10
25
+ employees %>%
26
+ filter(dept_id == 10)
27
+ 🔹 2. Mutating Joins (left_join)
28
+ r
29
+ Copy
30
+ Edit
31
+ # Add department name to employees
32
+ employees %>%
33
+ left_join(departments, by = "dept_id")
34
+ 🔹 3. Inner Join
35
+ r
36
+ Copy
37
+ Edit
38
+ # Only matching employees with department info
39
+ employees %>%
40
+ inner_join(departments, by = "dept_id")
41
+ 🔹 4. Handling Duplicate Keys
42
+ r
43
+ Copy
44
+ Edit
45
+ # Add a duplicate dept row
46
+ departments2 <- rbind(departments, data.frame(dept_id = 10, dept_name = "HR-Duplicate"))
47
+
48
+ # Join - will create multiple rows for duplicate keys
49
+ employees %>%
50
+ left_join(departments2, by = "dept_id")
51
+ 🔹 5. Defining Key Column (custom join keys)
52
+ r
53
+ Copy
54
+ Edit
55
+ emp <- data.frame(id = c(1, 2), val = c("A", "B"))
56
+ ref <- data.frame(key = c(1, 2), desc = c("X", "Y"))
57
+
58
+ emp %>%
59
+ left_join(ref, by = c("id" = "key"))
60
+ 🔹 6. Filtering Joins
61
+ r
62
+ Copy
63
+ Edit
64
+ # Semi Join: Keep rows in employees that match departments
65
+ employees %>%
66
+ semi_join(departments, by = "dept_id")
67
+
68
+ # Anti Join: Keep rows in employees that don't match departments
69
+ employees %>%
70
+ anti_join(departments, by = "dept_id")
71
+ 🔹 7. Set Operations
72
+ r
73
+ Copy
74
+ Edit
75
+ a <- data.frame(x = c(1, 2, 3))
76
+ b <- data.frame(x = c(2, 3, 4))
77
+
78
+ # Union (unique values)
79
+ union(a, b)
80
+
81
+ # Intersect (common values)
82
+ intersect(a, b)
83
+
84
+ # Set difference (in a but not in b)
85
+ setdiff(a, b)
@@ -0,0 +1,71 @@
1
+ ✅ Step 1: Load tidyr and dplyr
2
+ r
3
+ Copy
4
+ Edit
5
+ library(tidyr)
6
+ library(dplyr)
7
+ 🔹 Sample Data
8
+ r
9
+ Copy
10
+ Edit
11
+ data <- data.frame(
12
+ name = c("Alice", "Bob"),
13
+ math = c(90, 85),
14
+ science = c(95, 80)
15
+ )
16
+ 🔹 1. Gathering → pivot_longer()
17
+ r
18
+ Copy
19
+ Edit
20
+ data_long <- data %>%
21
+ pivot_longer(cols = c(math, science), names_to = "subject", values_to = "score")
22
+
23
+ print(data_long)
24
+ 🔹 2. Spreading → pivot_wider()
25
+ r
26
+ Copy
27
+ Edit
28
+ data_wide <- data_long %>%
29
+ pivot_wider(names_from = subject, values_from = score)
30
+
31
+ print(data_wide)
32
+ 🔹 3. Separate Columns
33
+ r
34
+ Copy
35
+ Edit
36
+ full_name <- data.frame(name = c("Alice_Smith", "Bob_Jones"))
37
+
38
+ # Separate name into first and last
39
+ full_name_sep <- full_name %>%
40
+ separate(name, into = c("first_name", "last_name"), sep = "_")
41
+
42
+ print(full_name_sep)
43
+ 🔹 4. Unite Columns
44
+ r
45
+ Copy
46
+ Edit
47
+ # Combine first_name and last_name
48
+ full_name_united <- full_name_sep %>%
49
+ unite("full_name", first_name, last_name, sep = " ")
50
+
51
+ print(full_name_united)
52
+ 🔹 5. Handling Missing Values
53
+ r
54
+ Copy
55
+ Edit
56
+ missing_data <- data.frame(
57
+ name = c("A", "B", "C"),
58
+ score = c(85, NA, 90)
59
+ )
60
+
61
+ # Remove rows with NA
62
+ missing_data_clean <- missing_data %>%
63
+ drop_na()
64
+
65
+ # Replace NA with value
66
+ missing_data_filled <- missing_data %>%
67
+ replace_na(list(score = 0))
68
+
69
+ print(missing_data_clean)
70
+ print(missing_data_filled)
71
+ Let m