gene_a <- 120
gene_b <- 200
combined_expression <- gene_a + gene_b
combined_expression
## [1] 320
run1 <- 500000
run2 <- 600000
total_read_pairs <- run1 * run2
total_read_pairs
## [1] 3e+11
control <- 300
treated <- 150
fold_change <- treated / control
fold_change
## [1] 0.5
lane_capacity <- 250000
total_reads <- 1001000
leftover_reads <- total_reads %% lane_capacity
leftover_reads
## [1] 1000
gene_x_count <- 350
gene_x_count
## [1] 350
patient_a <- 100
patient_b <- 120
total_expression <- patient_a + patient_b
total_expression
## [1] 220
patient_b_updated <- 130
total_expression <- patient_a + patient_b_updated
total_expression
## [1] 230
marker_gene <- "CD274"
marker_gene
## [1] "CD274"
x <- 100
class(x)
## [1] "numeric"
gene_name <- "TP53"
class(gene_name)
## [1] "character"
is_marker <- TRUE
class(is_marker)
## [1] "logical"
counts <- c(120, 150, 130)
counts
## [1] 120 150 130
names(counts) <- c("TP53", "BRCA1", "EGFR")
counts
## TP53 BRCA1 EGFR
## 120 150 130
print(counts)
## TP53 BRCA1 EGFR
## 120 150 130
names(counts)
## [1] "TP53" "BRCA1" "EGFR"
counts["EGFR"]
## EGFR
## 130
counts[1:2]
## TP53 BRCA1
## 120 150
samples <- c("Sample1", "Sample2", "Sample3")
samples
## [1] "Sample1" "Sample2" "Sample3"
genes <- c("TP53", "BRCA1", "EGFR")
counts <- c(120, 150, 130)
names(counts) <- genes
counts
## TP53 BRCA1 EGFR
## 120 150 130
class(counts)
## [1] "numeric"
patient_ids <- paste("Patient", 1:5, sep = "_")
patient_ids
## [1] "Patient_1" "Patient_2" "Patient_3" "Patient_4" "Patient_5"
mixed_vector <- c("TP53", 100, TRUE)
mixed_vector
## [1] "TP53" "100" "TRUE"
class(mixed_vector)
## [1] "character"
# All elements are coerced to character, since character is the
# most flexible type that can represent numbers, logicals, and text.
count_char <- "150"
count_numeric <- as.numeric(count_char)
count_numeric
## [1] 150
class(count_numeric)
## [1] "numeric"
x <- 5
y <- "6"
x + y
## Error in `x + y`:
## ! non-numeric argument to binary operator
# This fails with "non-numeric argument to binary operator" because
# y is a character string, not a number, and R cannot perform
# arithmetic between numeric and character types directly.
y <- as.numeric(y)
result <- x + y
result
## [1] 11
counts <- c(TP53 = 120, BRCA1 = 90, EGFR = 310)
high_expression_genes <- counts[counts > 100]
high_expression_genes
## TP53 EGFR
## 120 310