This is a test version of Biostars. For the public version, visit https://www.biostars.org.
average of one column for each category of another column

Hi, I want to have a table and a plot for showing the average cov of each chromosome in column 1 in R.

Thanks in advance!

head(data)
  chr    str      end   cov
 1       847      897    2
 1       14111    14161  8
 1       14270    14308  1
 1       14308    14320  6
 1       14320    14322  5
 1       14322    14358  9
r

Thanks, This command worked for me:

tapply(data$cov, df$cov, mean)

about the plots these two options work as well:

Option 1:

ggplot(df, aes(x = factor(age), y = score)) + 
  geom_bar(stat = "summary", fun = "mean")

Option 2:

ggplot(df, aes(x = factor(age), y = score)) + 
  stat_summary(fun = "mean", geom = "bar")

Now the question is how i can filter for specific chr column (for example just for chr 1:20)?

Hi

Try in R :

#For average
mean (Emb11$chr)

# For frequency
table(Emb11$chr)

They want to group by chr, and get mean of cov columns. See links in ATpoint's comment above.

0 answers

No answers yet.

Log in to answer this question.