debugging r code

Can someone help me debug this code to generate a normalization graph based on the data "GSE233767_mRNA_Expression_Profiling.xlsx" (download link: GEO Accession viewer )

This is my code to generate a normalization graph but it keeps giving me the same errors " Error in mutate():
:information_source: In argument: across(all_of(cols), ~./sum(.)).
Caused by error in across():
! Can't compute column ...10.
Caused by error in sum():
! invalid 'type' (character) of argument"


#load data 
data <- read_excel("file-path-to-data")

# Select columns for normalization
cols <- colnames(data)[10:17]

# Convert columns to character type
for (col in cols) {
  data[[col]] <- as.character(data[[col]])

# Define  gene_id variable
gene_id <- data$gene_id

# Normalize  selected columns
normalized_data <- data %>%
  mutate(across(all_of(cols), ~ ./sum(.)))

#  normalization plot
ggplot(normalized_data, aes(x = gene_id, y = value)) +
  geom_bar(stat = "identity", fill = "steelblue") +
  labs(x = "Gene ID", y = "Normalized Value", title = "Normalization Graph") +

Hi, the tenth column is a character and can't be summed. Maybe this could be converted to a numeric column first if it is a column that you want to sum.

Otherwise, next time please provide a reproducible example of your dataset (a few rows of sample data).

This explains the error.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.