Rstudio calculating mean trouble

Hello,

I am trying to calucate the mean of one of my columns "response" but it seems to come up with NH when I try to calculate it. Here

below is what I have typed in so far:

library(tidyverse)
library(tidyverse)
dat <- read_csv("Learningtask.csv")
tidydat <- dat %>% select(participant, response_age_a,response_age_b, response_gender, stage, trial_type, cue, correct_response, response, correct, rt, block_s1, count_s1, count_s2)
dat %>% head ()
dat%>% glimpse()
dat_clean <-
dat %>% select(participant,
trial_type,
stage,
cue,
correct_response,
response,
correct,
rt,
block_s1,
count_s1,
count_s2)

colnames(dat_clean) <- c("participant",
"trial_type",
"stage",
"cue",
"correct_response",
"response",
"correct",
"rt",
"block_s1",
"count_s1",
"count_s2")

exclude <- c(22617, 22638, 21470, 22557, 22666, 22701, 22714, 22736, 22759, 22806,23180, 23218, 23271, 23273, 23300, 23341, 23465, 23469, 22617,22638, 21470, 22557, 22736, 22759, 23218, 23341, 23465)
dat_clean <- dat_clean %>% filter(!(participant %in% exclude))

head(dat_clean)
nc_include2 <- dat_clean %>% filter(stage =="3") %>% drop_na()

nc_includead <- nc_include2 %>% filter (trial_type == "AD")

Once I have filtered out my data I type in this sentence:

nc_includead %>% summarise(mean(response))

and it comes up with this in the output:
nc_includead %>% summarise(mean(response))

A tibble: 1 x 1

mean(response)

1 NA
Warning message:
In mean.default(response) :
argument is not numeric or logical: returning NA

I was wondering if anyone could me understand why this is happening and how to fix it.

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Hello,

I am not sure if you mean this?

head(nc_includead)
# A tibble: 6 x 11
  participant trial_type stage cue   correct_response response correct    rt block_s1
        <dbl> <chr>      <dbl> <chr> <chr>            <chr>      <dbl> <dbl>    <dbl>
1       21433 AD             3 gree… z                1              0 11767       11
2       21433 AD             3 pink… z                3              0  2427       11
3       21550 AD             3 gree… z                5              0  1851       11
4       21550 AD             3 pink… z                5              0  3329       11
5       21602 AD             3 blue… z                1              0  2283       11
6       21602 AD             3 grey… z                5              0  1378       11
# … with 2 more variables: count_s1 <dbl>, count_s2 <dbl>

No I didnt mean that . Please read the document.
I promise you will benefit in the long run from taking a little time with it.

If you want to skip past the opening. You can look for the text beginning:

Now you just need to put this into

However, its clear now that response is a character vector rather than a numeric vector. so a conversion would be necessary

nc_include2 <- dat_clean %>% 
                    filter(stage =="3") %>% 
                    drop_na() %>%
                    mutate(response=as.numeric(response))

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.