R - Read in multiple files one-liner #1542
kubu4
started this conversation in
Show and tell
Replies: 1 comment
-
And, for some bonus content, here's how to name the dataframes in the list! # Save just the filenames to a vector
# By NOT using the `full.names = TRUE`
filenames <- list.files(path = "output/34-transcript-counts/", pattern = "diffs.max")
# Assign filenames to dataframes in list
names(diffs.max.tx.list) = filenames Here's how that same list looks now: List of 6
$ diffs.max.transcripts_per_gene.controls_females.vs.controls_males.csv :'data.frame': 5764 obs. of 4 variables:
..$ gene_name : chr [1:5764] "LOC111099035" "LOC111099036" "LOC111099040" "LOC111099043" ...
..$ control_females_max_transcript_counts: int [1:5764] 2 2 18 2 6 1 2 2 2 1 ...
..$ control_males_max_transcript_counts : int [1:5764] 1 1 13 1 5 2 3 1 4 2 ...
..$ difference : int [1:5764] 1 1 5 1 1 -1 -1 1 -2 -1 ...
$ diffs.max.transcripts_per_gene.controls_females.vs.exposed_females.csv:'data.frame': 3966 obs. of 4 variables:
..$ gene_name : chr [1:3966] "LOC111099031" "LOC111099040" "LOC111099043" "LOC111099059" ...
..$ control_females_max_transcript_counts: int [1:3966] 1 18 2 2 2 2 1 1 0 1 ...
..$ exposed_females_max_transcript_counts: int [1:3966] 0 17 1 1 1 5 2 0 1 0 ...
..$ difference : int [1:3966] 1 1 1 1 1 -3 -1 1 -1 1 ...
$ diffs.max.transcripts_per_gene.controls_males.vs.exposed_males.csv :'data.frame': 4327 obs. of 4 variables:
..$ gene_name : chr [1:4327] "LOC111099036" "LOC111099040" "LOC111099047" "LOC111099056" ...
..$ control_males_max_transcript_counts: int [1:4327] 1 13 5 3 1 4 1 2 2 2 ...
..$ exposed_males_max_transcript_counts: int [1:4327] 2 16 4 2 2 5 2 1 1 4 ...
..$ difference : int [1:4327] -1 -3 1 1 -1 -1 -1 1 1 -2 ...
$ diffs.max.transcripts_per_gene.controls.vs.exposed.csv :'data.frame': 2808 obs. of 4 variables:
..$ gene_name : chr [1:2808] "LOC111099040" "LOC111099043" "LOC111099070" "LOC111099076" ...
..$ controls_max_transcript_counts: int [1:2808] 18 2 4 1 2 1 5 2 4 1 ...
..$ exposed_max_transcript_counts : int [1:2808] 17 1 5 2 1 0 4 4 3 2 ...
..$ difference : int [1:2808] 1 1 -1 -1 1 1 1 -2 1 -1 ...
$ diffs.max.transcripts_per_gene.exposed_females.vs.exposed_males.csv :'data.frame': 5418 obs. of 4 variables:
..$ gene_name : chr [1:5418] "LOC111099031" "LOC111099035" "LOC111099040" "LOC111099047" ...
..$ exposed_females_max_transcript_counts: int [1:5418] 0 2 17 6 1 3 1 1 1 2 ...
..$ exposed_males_max_transcript_counts : int [1:5418] 1 1 16 4 2 2 3 2 2 1 ...
..$ difference : int [1:5418] -1 1 1 2 -1 1 -2 -1 -1 1 ...
$ diffs.max.transcripts_per_gene.females.vs.males.csv :'data.frame': 4420 obs. of 4 variables:
..$ gene_name : chr [1:4420] "LOC111099035" "LOC111099040" "LOC111099043" "LOC111099047" ...
..$ female_max_transcript_counts: int [1:4420] 2 18 2 6 1 2 1 1 1 1 ...
..$ male_max_transcript_counts : int [1:4420] 1 16 1 5 2 3 2 2 0 2 ...
..$ difference : int [1:4420] 1 2 1 1 -1 -1 -1 -1 1 -1 ... This allows you to refer to the dataframes in the list by name, like so: > str(diffs.max.tx.coordinates.circos.cvir.list[["diffs.max.transcripts_per_gene.controls_females.vs.controls_males"]]) 'data.frame': 5764 obs. of 4 variables:
$ chr : chr "cvirNC_035780.1" "cvirNC_035780.1" "cvirNC_035780.1" "cvirNC_035780.1" ...
$ start : int 502147 682820 802779 860083 2028071 2413119 2500364 2653510 2897281 2937551 ...
$ end : int 508829 730982 829369 865303 2046722 2424450 2508028 2664271 2904164 2937621 ...
$ difference: int 1 1 -1 -1 2 1 1 1 -1 -1 ... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Accidentally put this in a different repo yesterday. Doh! Anyway, per some discussions in lab meeting this week, I'm showing off some code that I'm excited about.
This will load in any files (in the specified location) which match the pattern you set. The data frames are stored in a list.
And, here's what the resulting list looks like:
Beta Was this translation helpful? Give feedback.
All reactions