~ubuntu-branches/ubuntu/oneiric/r-cran-genabel/oneiric

« back to all changes in this revision

Viewing changes to R/del.phdata.R

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2011-02-05 18:06:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110205180624-i1twt82zdpepmfxw
Tags: upstream-1.6-4
ImportĀ upstreamĀ versionĀ 1.6-4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#' delete phenotypes from phdata
 
2
#' 
 
3
#' This function is used to delete certain 
 
4
#' phenotypes from phenotypic part (phdata) 
 
5
#' of an object of \code{\link{gwaa.data-class}}
 
6
#' 
 
7
#' @param data an object of \code{\link{gwaa.data-class}}
 
8
#' @param what which phenotypes (variables) to delete, expressed 
 
9
#' as (vector of) names (character) or integer (column of 
 
10
#' phdata data frame)
 
11
#' @param all if 'all'=TRUE and 'what' is misisng, 
 
12
#' all phenotypes are deleted, and only the 'id' 
 
13
#' and 'sex' are kept
 
14
#' 
 
15
#' @author Yurii Aulchenko
 
16
#' 
 
17
#' @examples
 
18
#' data(srdta)
 
19
#' phdata(srdta)[1:5,]
 
20
#' srdta <- del.phdata(srdta,"qt1")
 
21
#' phdata(srdta)[1:5,]
 
22
#' srdta <- del.phdata(srdta,all=TRUE)
 
23
#' phdata(srdta)[1:5,]
 
24
#' 
 
25
#' 
 
26
 
 
27
del.phdata <- function(data,what,all=FALSE)
 
28
{
 
29
        if (class(data) != "gwaa.data") stop("data should be of gwaa.data-class");
 
30
        if (missing(what) && all) {
 
31
                cat("Deleting all data but 'id' and 'sex'\n")
 
32
                data@phdata <- data@phdata[,c("id","sex")]
 
33
                return(data)
 
34
        }
 
35
        if (missing(what)) stop("'what' could be missing only if 'all'=TRUE (delete all data)")
 
36
        if (is.integer(what)) what <- names(data@phdata)[what]
 
37
        
 
38
        if (any(what == "id")) stop("you can not delete 'id'")
 
39
        if (any(what == "sex")) stop("you can not delete 'sex'")
 
40
        
 
41
        nms <- names(data@phdata);
 
42
        tokeep <- nms[!(nms %in% what)];
 
43
        data@phdata <- data@phdata[,tokeep]
 
44
        return(data)
 
45
}
 
 
b'\\ No newline at end of file'