Recently Published

Document6
Data Frames
I explored the versatility of data frames in R, focusing on their ability to handle multiple data types within a single structure. I began by creating empty and populated data frames with numeric and character columns, then examined their dimensions using nrow(), ncol(), and dim(). I also practiced converting matrices to data frames with as.data.frame(), which offers flexibility in column types. Subsetting data frames using numeric, logical indexing, and column names proved essential for filtering and managing data efficiently. I further enhanced my skills by using subset(), transform(), and within() functions for streamlined data manipulation. Lastly, I worked on converting all columns or selectively converting factor columns to characters, a useful practice for data consistency in merging or exporting tasks.
Project 3- Data 607
Plot
# Fit the Kaplan-Meier model, stratifying by 'sex' > km_fit <- survfit(surv_object ~ Smoking_Status, data = clinical_survival_data) > > View(km_fit) > > # Plot the Kaplan-Meier survival curve > ggsurvplot(km_fit, data = clinical_survival_data, + pval = TRUE, # Add p-value for log-rank test + conf.int = TRUE, # Show confidence intervals + xlab = "Time in Days", # Label for x-axis + ylab = "Survival Probability", # Label for y-axis + legend.title = "Smoking Status", # Title for the legend + legend.labs = c("Nonsmoker", "Smoker"), # Labels for each group + risk.table = TRUE, # Show risk table below the plot + risk.table.height = 0.25, # Adjust the height of the risk table + ggtheme = theme_minimal()) # Use a minimal theme > >
Document
Problem Set 2
Problem Set 2
The Logical Class
the logical class in R, examining how logical operators handle different conditions and scenarios. I began by defining two numeric values, a and b, and used logical operators || and && to construct conditional statements. These operators efficiently evaluate expressions, short-circuiting when the result is determined by the first condition. Next, I explored coercion by converting a numeric value to a logical value using as.logical(). This demonstrated how non-zero numeric values are interpreted as TRUE. Finally, I investigated the behavior of logical operations involving NA. The results highlighted how NA propagates uncertainty, returning NA when the outcome is ambiguous, but yielding a definitive result when combined with FALSE.
Numeric classes and storage modes
I explored the numeric class in R, focusing on the distinction between doubles and integers, their types, and how they are handled in arithmetic operations. I began by defining two variables: a, a double with a decimal, and b, an integer denoted by the L suffix. Using typeof(), I confirmed that a is stored as a double and b as an integer. Both were verified as numeric using is.numeric(). I also examined the conversion of logical values to numeric, observing that as.numeric(FALSE) correctly returns 0, but remains a double rather than an integer. To further understand data type precision, I used is.double() to check the precision of different numeric inputs. Lastly, I performed a benchmarking exercise using the microbenchmark package to compare the performance of arithmetic operations on integers and doubles. This highlighted subtle differences in execution times, demonstrating the impact of choosing the appropriate numeric type in computational tasks. This exercise deepened my understanding of numeric classes and their significance in optimizing R code for performance and memory efficiency.
Plot
Document
Code along 9 DA
The Character Class
In this entry, I explored the basics of the character class in R, focusing on coercion and type verification. I began by defining a character string, "Avery analyzes data efficiently and effectively", and confirmed its type using the class() and is.character() functions. These checks ensured that the variable was correctly recognized as a character string. Next, I experimented with coercion. I converted a numeric string "42" into a numeric value using as.numeric(), which successfully returned 42. However, when I attempted to coerce the word "analyzes" into a numeric value, R returned NA and issued a warning about coercion. This exercise highlighted the importance of understanding data types and the limitations of coercion in R. Through these steps, I reinforced my understanding of handling character data and the significance of proper type management in R. This foundational knowledge is crucial for ensuring accurate data transformations and avoiding errors in data analysis workflows.