There are many other questions which read similar to this, but none address my query [in a way I understand]
I have multiple dataframes: 'snps' 'snp2' 'snp3' 'snp4' 'snp5' which all have the same format
library(tidyr)
library(TwoSampleMR)
glimpse(snps)
Rows: 4,873
Columns: 4
$ chrpos <chr> "6:39016574-39055519", "6:39016574-39055519", "6:39016574-39055519"
$ target <chr> "GL", "GL", "GL"
$ query <chr> "6:39016574-39055519", "6:39016574-39055519", "6:39016574-39055519"
$ name <chr> "rs113920163", "rs183723208", "rs555466268"
The only thing that differs is the 'target' column. I want to run a function from the TwoSampleMR package
glc <- extract_outcome_data(snps = snps$name, outcomes = 'ukb-a-583')
But I want to do this for the other dataframes, in a loop
I made a list of all the names in each of the 'snps..' dataframes called targets
glimpse(targets)
Rows: 11
Columns: 1
$ target <chr> "GL", "ML", "HL", "TD", "ED"
And have been trying to loop through
list <- targets$target
for(i in list)
l <- list()
{
[[i]] <- extract_outcome_data(snps = targets$target, outcomes = 'ukb-a-583')
}
Which runs the but the object it makes 'l' is empty but there is no error msg so I don't know what to change.
Thanks!
*** EDIT ***
I am now trying
my_files <- list.files(pattern = "*_files.txt")
my_data <- lapply(my_files, read.table)
for (i in 1:length(my_data)){
dat <- extract_outcome_data(snps = my_data$[i]$targets, outcomes='ukb-a-583'))))
}
It works fine until the for loop and the for loop does run. However this does not extract the information that I need. I think its due to the 'snps = my_data$[i]$targets' bit - how do I access the column 'targets' in each of my dataframes in the my_data list?
Thanks!