在Rscript中查找模式/正则表达式

时间:2012-12-11 14:37:48

标签: r awk grep rscript

我有一个简短的Rscript,它找到了具有以下输出的cohens kappa:

Cohen Kappa and Weighted Kappa correlation coefficients and confidence boundaries 
                 lower estimate upper
unweighted kappa 0.099     0.18  0.27
weighted kappa   0.313     0.51  0.71

 Number of subjects = 100

是否可以将cohen.kappa(数据)的输出传递给grep以分配kappa估计值,将下限/上限估计值传递给类似于csh的变量(即cohen.kappa(data)| grep / awk“未加权kappa“......

以下是完整的

脚本
    library(psych)

## We want R to look for command line arguments. 1 is path to data csv file. 2 is column1. 3 is column2. 4 is save file name
## example command line...
## KS sas_reporting_summary.csv myo_stress_score sas_stress_score

args <- commandArgs(TRUE)

## Now input data csv file into a data frame in R, and attach column names
data<-data.frame(read.csv(args[1]))
attach(data)


## Now build a matrix for the kappa test to use (might not need to but this seemds to work!specify the column data and save name

col1 <- data[,args[2]]
col1_lab <- args[2]
col2 <- data[,args[3]]
col2_lab <- args[3]
save <- args[4]

## Now build a matrix for the kappa test to use (might not need to but this seems to work!). Name the matrix cols with the specified names and then print on screen
## Not sure if this is needed cohen.kappa(cbind(col1,col2)) works equally well

data_mat <- matrix(c(col1,col2),ncol=2)
colnames(data_mat) = c(col1_lab,col2_lab)
row.names(data_mat) = paste(1:nrow(data_mat))
cat("\n")
data_mat

####################################################################################################
#
# Now for the stats
# This calls cohen.kappa1(x=x,w=w,n.obs=n.obs, alpha=alpha)
#   x - 2xn data with categorical values from 1 to p
#   w - weights: Set to be:
#               0 (on the diagonal) - unweighted kappa
#               (distance from the diagonal) off the diagonal)^2 - weighted kappa
#
#   n.obs = number of observations
#   alpha = Probability level for confidence intervals.
#
###################################################################################################

cohen.kappa(data_mat)

0 个答案:

没有答案