1

を使用してRに読み込んだ多くの行を含むファイルにテーブルがあります

data <-read.table("path/to/data.txt",header=TRUE, sep="\t",row.names=1)
            A1    A2    A3    B1    B2    B3
    Row1    1      3    2     3     2     6    
    Row2    3      2    1     3     6     7
    ...

次に、これを使用してフレームに読み込みました

df <-data.frame(data)

function() を実行して、各行の A サンプルと B サンプルを比較したいと思います。

function(A,B)

しかし、各行のデータ フレームから A のみと B のみを指定する方法がわかりません。データ テーブル全体に対して一度にこれを行う方法はありますか? データをフレームに読み込む必要がありますか?それとも最初の read.table データから直接作業できますか?

4

1 に答える 1

2

これを試して:

set.seed(001) # Generating some data
DF <- data.frame(A1=sample(1:9, 10, T),
                 A2=sample(1:9, 10, T),
                 A3=sample(1:9, 10, T),
                 B1=sample(1:9, 10, T),
                 B2=sample(1:9, 10, T),
                 B3=sample(1:9, 10, T))


sampA <- DF[,grep('A', names(DF))]  # Sample with columns A
sampB <- DF[,grep('B', names(DF))]  # Sample with columns B


lapply(1:nrow(DF), function(i){
  wilcox.test(as.numeric(sampA[i,]), as.numeric(sampB[i,]), exact=FALSE )
})  # Performing the test

結果は次のようになります。

[[1]]

    Wilcoxon rank sum test with continuity correction

data:  as.numeric(sampA[i, ]) and as.numeric(sampB[i, ]) 
W = 3, p-value = 0.6579
alternative hypothesis: true location shift is not equal to 0 


[[2]]

    Wilcoxon rank sum test with continuity correction

data:  as.numeric(sampA[i, ]) and as.numeric(sampB[i, ]) 
W = 0, p-value = 0.0722
alternative hypothesis: true location shift is not equal to 0 


[[3]]

    Wilcoxon rank sum test with continuity correction

data:  as.numeric(sampA[i, ]) and as.numeric(sampB[i, ]) 
W = 6, p-value = 0.6579
alternative hypothesis: true location shift is not equal to 0 

DF最初の 3 つの結果のみを示しました。10 行あるため、完全なリストの長さは 10です。

于 2012-10-16T13:46:39.710 に答える