D. Wang - 4 months ago 45

R Question

Getting started on an assignment with R, and I haven't really worked with it before, so apologies if this is basic.

`brain`

`para1 para2 para3 para4 para5 para6 para7`

FF 133 132 124 118 64.5 816932

highVAL = ifelse(brain$para2>=130,1, 0)

highVAL gives me a vector of 1's and 0's, categorized by para2.

I'm looking to perform a t-test on the mean para7 between two sets: rows that have para2 > 130 and those that have para2 < 130.

In Python, I would construct two new arrays and append values in, and perform a t-test there. Not sure how I would go about it in R.

Answer

You're closer than you think! Your `highVAL`

variable should be added as a new column to the `brain`

data frame:

```
brain$highVAL <- brain$FSIQ >= 130
```

This adds a true/false column to the dataset. Then you can run the test using `t-test`

's formula interface:

```
result <- t.test(MRIcount ~ highVAL, data = brain)
```