calculate_square <- function(number){
    result <- number * number
    return(result)
}
calculate_square(18)

calculate_gc <- function(dna) {
    gc_count <- 0
    for ( i in 1:nchar(dna)) {
        base <- substr(dna, i, i)
        if (base == "G" | base == "C"){
            gc_count <- gc_count + 1
        }
    }
    gc_percent <- (gc_count / nchar(dna)) * 100
    return(gc_percent)
}
calculate_gc("ATGCCGAT")

count_high_expression <- function(expression_data){
    high_count <- 0
    for (expression in expression_data) {
        if (expression > 10) {
            high_count <- high_count + 1
        }
    }
    return(high_count)
}
gene_expression <- c(12, 8, 20, 6, 5, 15)
count_high_expression(gene_expression)

add_numbers <- function(a, b) {
    result <- a + b
    return(result)
}
add_numbers(12, 22)

calculate_result <- function(x) {
    square <- function(number) {
        return(number * number)
    }
    result <- square(x)
    return(result)
}
calculate_result(44)

threshold <- 15
check_expression <- function(expression){
    if (expression > threshold) {
        print("high expression")
    } else {
        print("low expression")
    }
}
check_expression(16)
check_expression(8)

calculate_average <- function(expression_data){
    total <- sum(expression_data)
    n <- length(expression_data)
    average <- total / n
    return(average)
}
gene_expression <- c(12, 8, 20, 15, 5)
calculate_average(gene_expression)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: