[R] reading files

arun smartpink111 at yahoo.com
Tue Sep 3 15:42:44 CEST 2013



HI,

?list.files()
list.files()  #created 4 files in my working directory
#[1] "A_hubs.txt"    "A_nonhubs.txt" "B_hubs.txt"    "B_nonhubs.txt"

#If you want to do wilcox.test in a pairwise manner:


combn(list.files(),2)
#     [,1]            [,2]         [,3]            [,4]           
#[1,] "A_hubs.txt"    "A_hubs.txt" "A_hubs.txt"    "A_nonhubs.txt"
#[2,] "A_nonhubs.txt" "B_hubs.txt" "B_nonhubs.txt" "B_hubs.txt"   
 #    [,5]            [,6]           
#[1,] "A_nonhubs.txt" "B_hubs.txt"   
#[2,] "B_nonhubs.txt" "B_nonhubs.txt"


P_value<- sapply(as.data.frame(combn(list.files(),2),stringsAsFactors=FALSE),function(x){ x1<-read.table(x[1],sep="",header=TRUE); x2<- read.table(x[2],sep="",header=TRUE); wilcox.test(x1$TIS_SV,x2$TIS_SV)$p.value})

NAME<-gsub("[.txt]","",apply(as.data.frame(combn(list.files(),2),stringsAsFactors=FALSE),2, paste,collapse="_"))
res<- data.frame(NAME,P_value,stringsAsFactors=FALSE)
 row.names(res)<-1:nrow(res)
res
#                 NAME   P_value
#1    A_hubs_A_nonhubs 0.3684845
#2       A_hubs_B_hubs 0.1388408
#3    A_hubs_B_nonhubs 0.1531984
#4    A_nonhubs_B_hubs 0.7910863
#5 A_nonhubs_B_nonhubs 0.4926012
#6    B_hubs_B_nonhubs 0.6350055

A.K.



----- Original Message -----
From: anupam sinha <anupam.contact at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, September 3, 2013 6:58 AM
Subject: [R] reading files

Dear all,

I need help with some coding. I have a directory with files like these:

A_hubs
A_nonhubs
B_hubs
B_nonhubs
:
:
Each of these files have the following header and content:

GENE  TIS_DEG   TOT_SV    TIS_SV    TIS_DISO

ensg1   20                 12         4              40
.
.
and so on...

I want to calculate the p-value of the function
wilcox.test(A_hubs$TIS_SV,A_nonhubs$TIS_SV) and store it in a table of the
format

NAME   p-value

A           0.05

Can some give me pointers in the direction? Thanks in advance


Anupam

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list