[R] R CMD BATCH: unable to start device PNG

2006-11-03 Thread ryszard . czerminski
Dear r-helpers:

Any ideas how to avoid problem described below?
I am having the same problem when I run R remotly (not from cgi script);
somehow png device wants to talk to X11 and X11 complains...

Best regards,
Ryszard

error msg from batch R process (Linux/R-2.4.0) (executed on Apache server 
from cgi script):

Error in X11(paste("png::", filename, sep = ""), width, height, pointsize, 
 :
unable to start device PNG
In addition: Warning message:
unable to open connection to X11 display ''
Execution halted
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


[R] how to print table with more columns per row?

2006-07-20 Thread ryszard . czerminski
When printing a table it is broken at some point (depending how long are 
the associated names)
>>> see example below.

Is there a way to control number of columns being printed for a given 
chunk of the table?

Best regards,
Ryszard

> z5
AAA BBB CCC DDD EEE FFF GGG HHH 
III
AAA1.00   -0.69   -0.54   -0.88  NA  NA  NA  NA 
-0.88
BBB   -0.691.000.650.82  NA  NA  NA   1 
0.83
CCC   -0.540.651.000.49  NA  NA  NA  NA 
0.94
DDD   -0.880.820.491.00  NA  NA  NA   1 
0.90
EEE  NA  NA  NA  NA  NA  NA  NA  NA  
NA
FFF  NA  NA  NA  NA  NA  NA  NA  NA  
NA
GGG  NA  NA  NA  NA  NA  NA  NA  NA  
NA
HHH  NA1.00  NA1.00  NA  NA  NA   1  
NA
III   -0.880.830.940.90  NA  NA  NA  NA 
1.00
JJJ  NA  NA  NA  NA  NA  NA  NA  NA  
NA
KKK0.050.210.11   -0.11  NA  NA  NA   1  
NA
LLL0.73   -0.68   -0.16   -0.91  NA  NA  NA  -1 
-0.35
JJJ KKK LLL
AAA  NA0.050.73
BBB  NA0.21   -0.68
CCC  NA0.11   -0.16
DDD  NA   -0.11   -0.91
EEE  NA  NA  NA
FFF  NA  NA  NA
GGG  NA  NA  NA
HHH  NA1.00   -1.00
III  NA  NA   -0.35
JJJ  NA  NA  NA
KKK  NA1.000.24
LLL  NA0.241.00
>

CONFIDENTIALITY NOTICE\ \ The information contained in this ...{{dropped}}

__
R-help@stat.math.ethz.ch 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.


[R] strange matrix behaviour: is there a matrix with one row?

2006-04-07 Thread ryszard . czerminski
Consider this:

> y <- matrix(1:8, ncol=2)
> is.matrix(y[-c(1,2),])
[1] TRUE
> is.matrix(y[-c(1,2,3),])
[1] FALSE
> is.matrix(y[-c(1,2,3,4),])
[1] TRUE

It seems like an inconsistent behaviour:
- with 2 or more rows we have a matrix
- with 1 row we do not have a matrix and
- with 0 rows we have a matrix again

I just stumbled on this behaviour, because I had a problem
with my program in which I have assumed that matrix with
some rows removed is still a matrix, which seems to be mostly
true, but it is not true if only one row is left.

Comments? Suggestions?
How to work around this problem - without to many "if" statements?

Best regards,
Ryszard

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] how to initialize random seed properly ?

2004-06-10 Thread ryszard . czerminski
Here is my best solution so far using $RANDOM in bash
or maybe somebody has "pure R"  solution ?

#!/bin/bash
for i in 1 2; do
p=tmp$i
cat > $p.R << EOF
set.seed($RANDOM)
cat('rnorm(3) =', rnorm(3), '\n')
EOF
nice R CMD BATCH --no-save --no-restore $p.R $p.log &
done
sleep 3
grep rnorm tmp[12].log

Best regards,
Ryszard





Ryszard Czerminski/PH/[EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
06/09/2004 03:24 PM

 
To: [EMAIL PROTECTED]
cc: 
Subject:[R] how to initialize random seed properly ?


I want to start R processes on multiple processors from single shell 
script
and I want all of them to have different random seeds.
One way of doing this is

sleep 2 # (with 'sleep 1' I am often getting the same number)
   ...
set.seed(unclass(Sys.time()))

Is there a simpler way without a need to sleep between invoking
different R processes ?

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] how to initialize random seed properly ?

2004-06-09 Thread ryszard . czerminski
I want to start R processes on multiple processors from single shell 
script
and I want all of them to have different random seeds.
One way of doing this is

sleep 2 # (with 'sleep 1' I am often getting the same number)
   ...
set.seed(unclass(Sys.time()))

Is there a simpler way without a need to sleep between invoking
different R processes ?

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] R-1.9.0: Error in paste(ncomp, "LV's") : Argument "ncomp" is missing, with no default

2004-05-27 Thread ryszard . czerminski
Is it just my installation or bug in 1.9.0 ?
The same thing works fine in 1.8.1

Best regards,

Ryszard

# R-1.9.0
library(pls.pcr)
nr <- 8; ndim <- 2
x <- matrix(rnorm(nr*ndim), nrow=nr)
y <- as.matrix(x[,1])
for (i in 2:ndim) y <- y + x[,i]
y <- y + rnorm(length(y))
m <- pls(x,y,validation='CV')
# Error in paste(ncomp, "LV's") : Argument "ncomp" is missing, with no 
default

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] how to pass extra parameters using call() or similar mechanism ?

2004-03-11 Thread ryszard . czerminski
I am trying to write a function, which would allow to call various methods
and would pass to them extra arbitrary parameters.
My first attempt was to use call() as illustrated below, but apparently
'...' cannot be used in such context.

How can this be achieved ?

Best regards,

Ryszard

> myfun <- function(method, x, ...) {
+   v <- eval(call(method, x, ...))
+ }
> method = 'sqrt'
> myfun('sqrt',2)
Error in eval(call(method, x, ...)) : ... used in an incorrect context
> eval(call(method, 2, ...))
Error in eval(call(method, 2, ...)) : ... used in an incorrect context
> eval(call(method, 2))
[1] 1.414214

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] row.names are dropped when extracting one column ?

2004-03-02 Thread ryszard . czerminski
Apparently row names are dropped when I extract
single column from a data frame. Why this behaviour ?

> y <- as.matrix(df[,1:2]); length(row.names(y))
[1] 324
> y <- as.matrix(df[,1:1]); length(row.names(y))
[1] 0

Best regards,

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] problem with read.table

2004-02-03 Thread ryszard . czerminski
Any ideas why read.table complains about not correct number of elements in 
line
while readLine/strsplit indicate that all lines have the same number of 
elements ?

R


> tbl <- read.table('tmp', header = T, sep = '\t')
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = 
dec,  : 
line 32 did not have 27 elements
> lines <- readLines('tmp')
> v <- 1:length(lines)
> i <- 0; for (line in lines) { i <- i + 1; v[i] <- length(strsplit(line, 
'\t')[[1]]) }
> v
 [1] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 
27 27
[26] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 
27 27
[51] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27
> sum((v - v[1])^2)
[1] 0
> length(strsplit(lines[32], '\t')[[1]])
[1] 27

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] prcomp: error code 17 from Lapack routine dgesdd

2004-01-14 Thread ryszard . czerminski
I am trying to use prcomp and I am getting this error:

> p <- prcomp(xtr, retx = TRUE, center = TRUE, scale = TRUE, tol = NULL)
Error in La.svd(x, nu, nv, method) : error code 17 from Lapack routine 
dgesdd
> dim(xtr)
[1]  301 2439

Does it mean that the matrix is to big ?

R

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] tune(): how to specify a kernel ?

2004-01-12 Thread ryszard . czerminski
I would like to use tune() for tuning parameters for svm method, but it is 
not clear
to me how to specify a kernel.

I am trying to use something like this:

> obj <- tune(svm, Species~., data = iris, ranges = list(kernel = 
c('radial', 'linear')))
Error in pmatch(x, table, duplicates.ok) :
argument is not of mode character

but it generates an error.

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] dist(x,y)

2004-01-06 Thread ryszard . czerminski
Hi Erin,

CLARIFICATION: I am looking for function which can calculate distances 
between
rows in two different matrices (not in the same matrix as dist).
Of course I can get the desired result by using rbind() and fiddling with 
indices of the result, which I already did,
but I wonder if there is a function (or some variant of dist), which does 
it directly ?

Ryszard





Erin Hodgess <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
01/06/2004 12:41 PM

 
To: [EMAIL PROTECTED]
cc: 
Subject:[R] dist(x,y)


Hi Ryszard!

There is a dist function in R.
It's in the mva package.
You can set the kind of distance that you want.

Thanks,
Erin
mailto:[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] dist(x, y) ???

2004-01-06 Thread ryszard . czerminski
Is there a function in R (similar to dist) which would calculate
distances between rows in two different matrices ?

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] problem with pls(x, y, ..., ncomp = 16): Error in inherit s( x, "data.frame") : subscript out of bounds

2003-12-09 Thread ryszard . czerminski
Help for pls says:

> ?pls
[...]
Arguments:
...
   ncomp: the numbers of latent variables to be assessed in the
  modelling. Default is from one to the rank of 'X'.
[...]

so my assumption was (maybe wrong) that idea of ncomp parameter is to 
limit
number of assessed variables.

also, if called without crossvalidation it gives the same error:

> m <- pls(x, y, ncomp = 16)
Error in inherits(x, "data.frame") : subscript out of bounds

R







"Liaw, Andy" <[EMAIL PROTECTED]>
12/09/2003 12:50 PM

 
To: Ryszard Czerminski/PH/[EMAIL PROTECTED], [EMAIL PROTECTED]
cc: 
Subject:RE: [R] problem with pls(x, y, ..., ncomp = 16): Error in 
inherit s( x, 
"data.frame") : subscript out of bounds


I don't know the details of pls (in the pls.pcr package, I assume), but if
you use validation="CV", that says you want to use CV to select the best
number of components.  Then why would you specify ncomp as well?

Andy

> From: [EMAIL PROTECTED]
> 
> When I try to use ncomp parameter in pls procedure  I get 
> following error:
> 
> > library(pls.pcr)
> > m <- pls(x, y, validation = "CV", niter = 68, ncomp = 16)
> Error in inherits(x, "data.frame") : subscript out of bounds
> 
> Without ncomp parameter everything seems to work OK
> 
> > dim(x)
> [1]  68 116
> > dim(y)
> [1] 68  1
> > m <- pls(x, y, validation = "CV", niter = 68)
> > length(m$ncomp)
> [1] 67
> 
> Ryszard
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] problem with pls(x, y, ..., ncomp = 16): Error in inherits(x, "data.frame") : subscript out of bounds

2003-12-09 Thread ryszard . czerminski
When I try to use ncomp parameter in pls procedure  I get following error:

> library(pls.pcr)
> m <- pls(x, y, validation = "CV", niter = 68, ncomp = 16)
Error in inherits(x, "data.frame") : subscript out of bounds

Without ncomp parameter everything seems to work OK

> dim(x)
[1]  68 116
> dim(y)
[1] 68  1
> m <- pls(x, y, validation = "CV", niter = 68)
> length(m$ncomp)
[1] 67

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] plotting to postscript: how to control line width ?

2003-11-25 Thread ryszard . czerminski
When I use
plot(..., type = "line")  then ldw parameter makes a difference...

Because of large number of points overlapping I simply han an impression
before that I am getting thick line...

R





Ryszard Czerminski/PH/[EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
11/25/2003 01:34 PM

 
To: [EMAIL PROTECTED]
cc: 
Subject:[R] plotting to postscript: how to control line width ?


How to control line width ?

if I do:

> postscript("IC50-density.eps", width = 4.0, height = 3.0, horizontal = 
FALSE, onefile = FALSE, paper = "special", title = "IC50 distribution")
> plot(d$x, d$y, xlab = "-log10(IC50)", ylab = "density")
> lines(d$x, d$y, lwd = 0.1)
> dev.off()

but whatever value I give for ldw parameter (e.g. 0.1 or 10) I am getting 
the same line width ?!

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] plotting to postscript: how to control line width ?

2003-11-25 Thread ryszard . czerminski
How to control line width ?

if I do:

> postscript("IC50-density.eps", width = 4.0, height = 3.0, horizontal = 
FALSE, onefile = FALSE, paper = "special", title = "IC50 distribution")
> plot(d$x, d$y, xlab = "-log10(IC50)", ylab = "density")
> lines(d$x, d$y, lwd = 0.1)
> dev.off()

but whatever value I give for ldw parameter (e.g. 0.1 or 10) I am getting 
the same line width ?!

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] index of max value ?

2003-11-14 Thread ryszard . czerminski
Is there a function in R, which would return index of maximum value
in a vector ?

e.g.

> v <- round(10*rnorm(8))
> v
[1]   6  -3  -6  15   7   9   0 -19
> max(v)
[1] 15

??? index.max(v)
??? 4

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] column extraction by name ?

2003-11-12 Thread ryszard . czerminski
I have a data frame (df) with colums x, y and z.
e.g.  df <- data.frame(x = sample(4), y = sample(4), z = sample(4))
I can extract column z by: df$z or df[3]
I can also extract columns x,y by: df[1:2] or by df[-3].

Is it possible to extract x,y columns in a "symbolic" fashion i.e.
by equivalent of df[-z] (which is illegal) ???

Or alternativeley, is there an equivalent of "index" function,
which would return index of the column given name ?

Ryszard

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] svm in e1071 package: polynomial vs linear kernel

2003-11-03 Thread ryszard . czerminski
I am trying to understand what is the difference between linear and 
polynomial kernel:

  linear: u'*v

  polynomial: (gamma*u'*v + coef0)^degree

It would seem that polynomial kernel with gamma = 1; coef0 = 0 and degree 
= 1
should be identical to linear kernel, however it gives me significantly 
different results  for very simple
data set, with linear kernel significantly outperforming polynomial 
kernel.

*** mse, r2 = 0.5, 0.9 for linear
*** mse, r2 = 1.8, 0.1 for polynomial

What am I missing ?

Ryszard

P.S.

Here are my results:

# simple cross validation function
cv.svm <- function(formula, data, ntry = 3, kernel = "linear", scale = 
FALSE, cross = 3,
   gamma = 1/(dim(data)-1), degree = 3) {
   mse <- 0; r2 <- 0
   for (n in 1:ntry) {
  svm.model <- svm(formula , data = data, scale = scale, kernel = 
kernel,
   cross = cross)
  mse <- mse + svm.model$tot.MSE
  r2  <- r2 + svm.model$scorrcoeff
   }
   mse <- mse/ntry; r2 <- r2/ntry; result <- c(mse, r2)
   cat(sprintf("cv.svm> mse, r2 = %5.3f %5.3f\n", mse, r2))
   return (result)
}

# define data set

x1 <- rnorm(9); x2 <- rnorm(9)
df <- data.frame(y = 2*x1 + x2, x1, x2)

#  invoke cv.svm() for linear and polynomial kernels few times

> r <- cv.svm( y ~ ., df, kernel = "polynomial", gamma = 1, degree = 1, 
ntry = 32)
cv.svm> mse, r2 = 1.888 0.162
> r <- cv.svm( y ~ ., df, kernel = "polynomial", gamma = 1, degree = 1, 
ntry = 32)
cv.svm> mse, r2 = 1.867 0.146
> r <- cv.svm( y ~ ., df, kernel = "polynomial", gamma = 1, degree = 1, 
ntry = 32)
cv.svm> mse, r2 = 1.818 0.105
> r <- cv.svm( y ~ ., df, kernel = "linear", gamma = 1, degree = 1, ntry = 
32)
cv.svm> mse, r2 = 0.525 0.912
> r <- cv.svm( y ~ ., df, kernel = "linear", gamma = 1, degree = 1, ntry = 
32)
cv.svm> mse, r2 = 0.537 0.878
> r <- cv.svm( y ~ ., df, kernel = "linear", gamma = 1, degree = 1, ntry = 
32)
cv.svm> mse, r2 = 0.528 0.913


[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] problem with tune.svm

2003-10-31 Thread ryszard . czerminski
> rng <- list(gamma = 2^(-1:1), cost = 2^(2:4))
> rng
$gamma
[1] 0.5 1.0 2.0

$cost
[1]  4  8 16

> obj <- tune.svm(pIC50 ~ ., data = data, ranges = rng)
Error in tune(svm, train.x = x, data = data, ranges = ranges, ...) :
formal argument "ranges" matched by multiple actual arguments

Ay idea why ???

Ryszard

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] strange sprintf() behaviour ?

2003-10-31 Thread ryszard . czerminski
This is quite strange behaviour - at least for R-novice as myself

Consider this:

> testf <- function() { x <-2; sprintf("%s %f", "x =", x); return(x) }
> result <- testf()
> testf <- function() { x <-2; sprintf("%s %f", "x =", x) }
> result <- testf()
> testf()
[1] "x = 2.00"

Apparently  adding return() statement and invoking function like this 
"result <- testf()"
suppresses output from sprintf()

Output from print() is NOT suppressed:

> testf <- function() { x <-2; print(c("x =", x)) }
> result <- testf()
[1] "x =" "2"
> testf <- function() { x <-2; print(c("x =", x)); return(x) }
> result <- testf()
[1] "x =" "2"

Is there a way to use sprintf() inside a function ?

I guess I can say: print(sprintf()) - is it the only solution for this ?

R

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] print(), cat() and simple I/O in R

2003-10-31 Thread ryszard . czerminski
I am trying to produce rather mundane output of the form e.g.

pi, e = 3.14   2.718

The closest result I achieved so far with print() is:

> print (c(pi, exp(1)), digits = 3)
[1] 3.14 2.72

> print(c("pi, e =", pi, exp(1)), digits = 3)
[1] "pi, e ="  "3.14159265358979" "2.71828182845905"
I understand that c() promotes floats to strings and this is why I get 
what I get.

and with cat() (it apparently does not have equivalent of digits" 
parameter)
> cat ("pi, e =", pi, exp(1), "\n")
pi, e = 3.141593 2.718282

Any pointers with respect how can I print what I want to print would be 
greatly appreciated.


Ryszard
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] svm from e1071 package

2003-10-29 Thread ryszard . czerminski
I am starting to use svm from e1071 and I wonder how exactly 
crossvalidation is implemented.
Whenever I run

> svm.model <- svm(y ~ ., data = trainset, cross = 3)

on my data I get dirrerent values for svm.model$MSE e.g. 
[1] 0.9517001 1.7069627 0.6108726
[1] 0.3634670 0.9165497 1.4606322

This suggests to me that data are scrambled each time - the last time I 
looked at libsvm python interface
this is what was done. Is this the same here (I hope) ?

R
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] how to remove NaN columns ?

2003-10-27 Thread ryszard . czerminski
I received a lot of good advice how to remove NaN columns - thank you all 
!!!
The simplest mechanism to center/scale and remove NaN columns seems to be

> xdata <- data.frame(A = 3:1, B = 1:3, rep(9, 3))
> xs <- scale(xdata)
> mask <- sapply(as.data.frame(xs), function(x) all(is.nan(x)))
> scaled.centered.x <- as.data.frame(xs)[!mask]
> scaled.centered.x
   A  B
1  1 -1
2  0  0
3 -1  1

Note that as.data.frame(xs) is important, because apparently xs from 
scale() function
is not a data frame and if as.data.frame() is omitted in the code fragment 
above we get something like this

> mask <- sapply(xs,  function(x) all(is.nan(x)))
> xs[!mask]
   123   
   10   -1   -101
 

Maybe somebody more knowledgeable could give some explanation for this 
behavior.

Ryszard
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] how to select random rows ?

2003-10-27 Thread ryszard . czerminski
How can I select random subsets (rows!) from a data set ?

If I generate simple data set

> a <- data.frame(x=1:2, y = NaN, z = 2:1)
> a
  x   y z
1 1 NaN 2
2 2 NaN 1

I can select random subsets (colums) very easily using sample function:

> sample(a, 2)
  z   y
1 2 NaN
2 1 NaN

I expected that using transpose of a would do the same for rows, but I am 
getting
rather unexpected outcome

> sample(t(a), 1)

   1

R

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] how to remove NaN columns ?

2003-10-24 Thread ryszard . czerminski
Nice!

I noticed that in generated structure it has two attributes 
attr(,"scaled:center") and attr(,"scaled:scale")
How can I access them ? 

R





Giovanni Petris <[EMAIL PROTECTED]>
10/24/2003 02:50 PM
Please respond to Giovanni Petris

 
To: Ryszard Czerminski/PH/[EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
Subject:Re: [R] how to remove NaN columns ?



> > xs <- lapply(xdata, function(x){(x - mean(x))/sqrt(var(x))})

Incidentally, the function 'scale' does just that.

-- 

 __
[  ]
[ Giovanni Petris [EMAIL PROTECTED] ]
[ Department of Mathematical Sciences  ]
[ University of Arkansas - Fayetteville, AR 72701  ]
[ Ph: (479) 575-6324, 575-8630 (fax)   ]
[ http://definetti.uark.edu/~gpetris/  ]
[__]




[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] How to avoid converting "_" to "." ?

2003-10-24 Thread ryszard . czerminski
It is minor thing, but how can I avoid converting "_" to "." ?

e.g. I have a data set "test.csv"
 
A,A_B,A_C,C,D
X,11,0,13,14
Y,21,0,23,24

and when I read it all underscores are converted to dots (:<)

> d <- read.csv("test.csv")
> d
  A A.B A.C  C  D
1 X  11   0 13 14
2 Y  21   0 23 24


Ryszard
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] how to remove NaN columns ?

2003-10-24 Thread ryszard . czerminski
How can I remove columns with NaN entries ?

Here is my simple example:

> data <- read.csv("test.csv")
> xdata <- data[3:length(data)]
> xs <- lapply(xdata, function(x){(x - mean(x))/sqrt(var(x))})
> x <- data.frame(xs)
> x
   C D   EF
1 -0.7071068 NaN -0.7071068 -0.7071068
2  0.7071068 NaN  0.7071068  0.7071068

I am sure it is possible to remove column D (with NaN's) in some simple 
fashion, using is.nan function
without explicitly looping through, and I am sure I was able to do it in 
the past, but I cannot recall how.

Your help will be greatly appreciated.

Ryszard

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help