average of one column for each category of another column
0
0
Entering edit mode
12 weeks ago
sata72 • 0

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 • 449 views
ADD COMMENT
1
Entering edit mode

Did you try anything before? Please google "average by group in R", there is a great many solutions already available.

See:

ADD REPLY
0
Entering edit mode

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)?

ADD REPLY
0
Entering edit mode

Hi

Try in R :

#For average
mean (Emb11$chr)

# For frequency
table(Emb11$chr)
ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1901 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6