rdata-analysisresearchkit

how can I combine three tables - 2 separate questionnaires used on the same cohort and one table with blood results


I have the results of a study looking at some blood results for thyroid function and questionnaires at the start and end of the study. I want to be able to analyse the results in rstudio for individual participants and identify whether any of the individual questions were better predictors of thyroid function. Completely new to this!

I haven't tried anything yet but have the data in csv files


Solution

  • What you are looking for is a "join" function. This will allow you to combine two data frames based on a shared column (in your case, likely a patient identifier). This is how it might look like

    library(tidyverse)
    
    # read in csvs
    blood_study <- read.csv("blood_results.csv")
    questionnaires  <- read.csv("questionnaires.csv")
    
    combined <- left_join(
        blood_study,
        questionnaires,
        by = "patientID" # Replace "patientID" with the actual name of the column in your data that uniquely identifies participants
    )
    

    If you have more than 2 tables, you can just perform another join command.