-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_dictionary.R
More file actions
32 lines (27 loc) · 927 Bytes
/
Data_dictionary.R
File metadata and controls
32 lines (27 loc) · 927 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
29
30
31
32
# Create a sample data frame
data <- data.frame(
ID = c(1, 2, 3, 4, 5),
Name = c("John", "Jane", "Mike", "Sarah", "David"),
Age = c(25, 32, 41, 29, 36),
Salary = c(50000, 60000, 70000, 55000, 80000),
stringsAsFactors = FALSE
)
# Create a function to generate the data dictionary
createDataDictionary <- function(data) {
dict <- data.frame(
Variable = names(data),
Type = sapply(data, class),
Description = NA,
stringsAsFactors = FALSE
)
return(dict)
}
# Generate the data dictionary
dataDictionary <- createDataDictionary(data)
# Add descriptions to the data dictionary
dataDictionary$Description[1] <- "Unique identifier for each individual"
dataDictionary$Description[2] <- "Name of the person"
dataDictionary$Description[3] <- "Age of the person"
dataDictionary$Description[4] <- "Salary of the person"
# Print the data dictionary
print(dataDictionary)