Table Creation (Newbie)

Hello,

i am just getting into R and am having a hard time getting started. Currently I am trying to get my Data into a specific graph but i don't really know how to do it.
This is an Example Table similar to that in R just much smaller:

R

What I want is:

  1. A graph that shows me the average of Cat B
  2. A graph that shows me the average of Cat B but only from "A" in Cat A
  3. A graph that shows me the average of Cat B but only from "B" in Cat A

I have tried working with plots and barplots in all kind of forms and the summary function. But to be honest I have no idea what i am doing and I am getting some usefull graphs but not the ones i want. I can't seem to get an average. How does that work?

really hoping somebody can help a newcomer out :slight_smile:
Thanks.

Good luck diving in - if you are new to coding it can definitely be confusing at first.
I'd recommend taking a look at the Software Carpentry R tutorials - taking some time to work through some examples will help you feel a bit more confident :slight_smile: : Programming with R

To make a plot of the average of Cat B this sounds like it will be a single point (e.g. mean of all the values in rows 2 to 9). Is that what you are trying to do?

Cheers

Hi :wave: and welcome to RStudio Community!

Like all programming languages, it takes some time to get up and running in R. If you're coming to R from another programming language there can also be a bit of a learning curve because things are a little different here.

You can get your data into a data.frame named df with this:

df <- data.frame(
  CatA = c("A", "A", "A", "A", "B", "B", "B", "B"),
  CatB = c(50, 100, 101, 888, 444, 333, 222, 111),
  CatC = c(999, 454, 5, 214, 56, 24, 12, 45)
)

The R function for calculating an average is mean(). To get the mean of all the values in CatB you can say mean(df$CatB), which passes the values in the CatB variable (i.e., column) of your data.frame and returns a single value. To get only certain values of the CatB variable you can subset your data.frame, limiting the selected values to just certain observations (i.e., rows).

The RStudio web site has great resources for learning R. Have a look and you'll soon be making progress.

1 Like

This topic was automatically closed 21 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.