-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram2.R
More file actions
28 lines (22 loc) · 697 Bytes
/
Program2.R
File metadata and controls
28 lines (22 loc) · 697 Bytes
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
# Create the initial data frame
df1 <- data.frame(
Name = c("Ram", "Alwin", "Billy", "Amera", "Olive", "Dora"),
Age = c(30, 35, 22, 16, 42, 59),
Height = c(177, 164, 155, 180, 124, 150),
Weight = c(57, 48, 45, 60, 52, 55),
Gender = c("M", "F", "M", "F", "F", "F"),
stringsAsFactors = FALSE
)
print(df1)
# Invert the gender for all individuals
df1$Gender <- ifelse(df1$Gender == "M", "F", "M")
# Create the second data frame
df2 <- data.frame(
Name = c("Ram", "Alwin", "Billy", "Amera", "Olive", "Dora"),
Working = c("Y", "N", "Y", "N", "Y", "N"),
stringsAsFactors = FALSE
)
print(df2)
# Combine the data frames column-wise
df_combined <- cbind(df1, df2)
print(df_combined)