Correlation in Columns (comparing two different exp. tasks) that have NAs

Hey everyone,

I'm in kind of a data frame conundrum here. Essentially I have two experimental tasks (i.e., Task 1 and Task 2), where I want to run a simple correlation on the entire data frame but , as you can probably see, the NAs won't allow me to find a correlation between tasks. And I can't drop or impute them either.

I tried several different manuvers and a pairwise deletion but I'm still getting NAs like in the output below.

Does anyone have a solution to this? I need the correlation between Task_1 and Task_2. I honestly stumped. The code below can replicate the screenshots and would be best to work a solution with. Than

library(tidyverse)

set.seed(123)

data <- data.frame(
  Task_1A = rnorm(10),
  Task_1B = rnorm(10),
  Task_2A = rnorm(10),
  Task_2B = rnorm(10),
  Col5 = rnorm(10),
  Col6 = rnorm(10),
  Col7 = rnorm(10),
  Col8 = rnorm(10)
)

data$Task_1A[c(1, 2, 3, 4, 5)] <- NA  
data$Task_1B[c(1, 2, 3, 4, 5)] <- NA  
data$Task_2A[c(6, 7, 8, 9, 10)] <- NA
data$Task_2B[c(6, 7, 8, 9, 10)] <- NA


Corr <- cor(data, use = "pairwise.complete.obs")

Thanks

Not doable. Nothing to do with R. Look at Task_1B and Task_2A. They have no data in common, so there's no way to get a correlation.

2 Likes

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