patch from David Skalinder
[iramuteq] / Rscripts / Rfunct.R
1 ColType <- function(x) {
2 #x data.frame
3     type<-character()
4     for (i in 1:ncol(x)) {
5         tmp<-as.matrix(x[,i])
6         type[i]<-mode(tmp)
7     }
8     type
9 }
10
11 LevelsNb<- function(x) {
12     levelsnb<-numeric()
13     for (i in 1:ncol(x)) {
14         if (mode(as.matrix(x[,i]))=="character") {
15             levelsnb[i]<-length(levels(x[,i]))
16         }
17         else {
18             levelsnb[i]<-NA
19         }
20     }
21     levelsnb
22 }
23
24 ReadData<- function(filename,sep=';',quote='"', header=TRUE, encoding='', na.strings ='',rownames=NULL) {
25     if (version$os=='linux-gnu') {
26         dataimport<-read.csv2(file(filename,encoding=encoding), header=header, sep=sep, quote=quote, na.strings='',row.names=rownames)
27     } else {
28         dataimport<-read.csv2(filename,encoding=encoding, header=header,sep=sep, quote=quote,na.strings='',row.names=rownames)
29     }
30     dataimport
31 }
32             
33 testzero<-function(mydata) {
34     nc<-vector()
35     nl<-vector()
36     for (i in 1:ncol(mydata)) {
37         if (sum(mydata[,i])==0) {
38             print('zero')
39             nc<-append(nc,i)
40         }
41     }
42     print('suite')
43     for (j in 1:nrow(mydata)) {
44         print(j)
45         if (sum(mydata[j,])==0) {
46             print('zero')
47             nl<-append(nl,j)
48         }
49     }
50     c(nc,nl)
51 }