[R] Trailing path separators and dirname(), file.exists(), file.path()

2016-11-12 Thread Dave Gerrard
I've found something irritating in the behaviour of dirname() and
subsequent interactions with file.path() and file.exists().  The problem is
how it and they deal with trailing path separators.   It seems the code is
correct to specification but I think it could be better. Part of the
problem is restricted to Windows and this is alluded to in the docs but the
implications are not fully explicit. Providing a path with a trailing path
separator to dirname() causes the final directory to be removed.


In Linux (R 3.3.1)

> file.path("","p1","p2","p3")
[1] "/p1/p2/p3"
> dirname(file.path("","p1","p2","p3")) # p3 is treated as a filename,
not a directory in the path - fine.
[1] "/p1/p2"
> file.path("","p1","p2","p3","/") # not the "//" by file.path"
[1] "/p1/p2/p3//"
> dirname(file.path("","p1","p2","p3","/"))# p3 is now treated as a
directory  - fine.
[1] "/p1/p2/p3"
> dirname("/p1/p2/p3/") # but when I give a path with no file at the end.
What I consider a directory, is chopped off as a final filename.
[1] "/p1/p2"



In Windows (R 3.3.1)

>  file.path("","p1","p2","p3") # as per linux
[1] "/p1/p2/p3"
> dirname(file.path("","p1","p2","p3"))  # as per linux
[1] "/p1/p2"
> file.path("","p1","p2","p3","/") # N.B. no second "/"
[1] "/p1/p2/p3/"
> dirname(file.path("","p1","p2","p3","/")) # last 'directory' lost
[1] "/p1/p2"
> dirname("/p1/p2/p3/") # last 'directory' lost
[1] "/p1/p2"


This is a problem for me when testing for the existence of directories
(e.g. have I already made an output directory for this analysis)

In Windows (R 3.3.1)

> dir.create("temp")
> file.exists("temp")
[1] TRUE
> file.exists("temp/") # R on windows not recognising and removing the
trailing path separator.
[1] FALSE
> file.exists(dirname("temp/"))
[1] TRUE
> dirname("temp/")
[1] "."


On Linux, I can use a trailing separator, but I still shouldn't use
dirname() :-

> dir.create("temp")
> file.exists("temp")
[1] TRUE
> file.exists("temp/")
[1] TRUE
> file.exists(dirname("temp/"))   # false positive
[1] TRUE
> dirname("temp/")# what it is really testing for.
[1] "."



Does anyone else feel this is not as good as it should be?


I don't know how old this behavious is. I've only tested R 3.3.1 but the
docs for file.path() suggest there may have been some recent tinkering:-

"Trailing path separators are invalid for Windows file paths apart from ‘/’
and ‘d:/’ (although some functions/utilities do accept them), so as from R
3.1.0 a trailing / or \ is removed."

Dave Gerrard

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Variable 'A' is not a factor Error message

2016-11-12 Thread ahmed meftah
I am running a DOE with the following code   library(Rcmdr)
library(RcmdrMisc)
library(RcmdrPlugin.DoE)
# Define plackett burman experiment
PB.DOE <- pb(nruns= 12 ,n12.taguchi= FALSE ,nfactors= 12 -1, ncenter= 0 ,
 replications= 1 ,repeat.only= FALSE ,randomize= TRUE ,seed= 
27241 , 
 factor.names=list( 
A=c(100,1000),B=c(100,200),C=c(1,3),D=c(1,1.7),
E=c(1000,1500),G=c(-2,2) ) )

as.numeric2 <- function(x) as.numeric(as.character(x))

# Calculate response column
IP <- 
with(PB.DOE,(as.numeric2(A)*as.numeric2(B)*(5000-3000))/(141.2*as.numeric2(C)*as.numeric2(D)*(log(as.numeric2(E)/0.25)-(1/2)+as.numeric2(G
# Combine response column with exp design table
final_set <- within(PB.DOE, {
  IP<- 
((as.numeric2(A)*as.numeric2(B)*(5000-3000))/(141.2*as.numeric2(C)*as.numeric2(D)*(log(as.numeric2(E)/0.25)-(1/2)+as.numeric2(G
})I then ran a regression as follows:LinearModel.1 <- lm(IP ~ A + B + C + D 
+ E + G, 
data=final_set)
summary(LinearModel.1)Following this i wanted to run a predict using specified 
values as predictors in a Monte Carlo:n = 1
# Define probability distributions of predictors
A = rnorm(n,450,100)
hist(A,col = "blue",breaks = 50)

B = rnorm(n, 150,10)
hist(B,col = "blue",breaks = 50)

C = rnorm(n, 1.5, 0.5)
hist(C,col = "blue",breaks = 50)

D = runif(n,1.2,1.7)
hist(D,col = "blue",breaks = 50)

E = rnorm(n,1250,50)
hist(E,col = "blue",breaks = 50)

G = rnorm(n,0,0.5)
hist(G,col = "blue",breaks = 50)

MCtable <- data.frame(A=A,B=B,C=C,D=D,E=E,G=G)

for (n in 1:n) {
  N=predict(LinearModel.1,MCtable)
}

hist(N,col = "yellow",breaks = 10)I end up getting this error:"Warning in 
model.frame.default(Terms, newdata, na.action = na.action, xlev = 
object$xlevels) :
  variable 'A' is not a factor"Using str() to get some info on the 
LinearModel.1 and from what I understand seems to indicates that since the 
predictors A,B,C etc are factors with 2 levels I have to convert my data.frame 
table to factors aswell. Is that correct?Doing this would mean I would also 
need to specify the number of levels which would mean that since I have set my 
n to 1 would mean 1 levels for each factor. How would I go about doing 
this? Is there a better solution? Any help would be appreciated.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Average every 4 columns

2016-11-12 Thread Jim Lemon
Hi Miluj,
Perhaps you didn't get my previous email. Let your data frame be named "msdf":

block_col_summ<-function(x,step,block_size,FUN="mean") {
 dimx<-dim(x)
 return_value<-NA
 start<-1
 end<-start+block_size-1
 block_count<-1
 while(end <= dimx[2]) {
  return_value[block_count]<-
   do.call(FUN,list(as.matrix(x[,start:end]),na.rm=TRUE))
  block_count<-block_count+1
  start<-start+step
  end<-start+block_size-1
 }
 return(return_value)
}
# use the step and block size that you want
block_col_summ(msdf,4,4)

Jim


On Thu, Nov 10, 2016 at 3:29 AM, Miluji Sb  wrote:
> Dear all,
>
> I have a dataset with hundreds of columns, I am only providing only 12
> columns. Is it possible to take the mean of every four (or 12) columns
>  (value601, value602, value603, value604 etc.in this case) and repeat for
> the hundreds of columns? Thank you.
>
> Sincerely,
>
> Milu
>
> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
> c(22.0399188995361,
> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
> c(33.9698333740234,
> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
> c(27.5402088165283,
> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
> c(9.12979793548584,
> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
> 6.65576601028442)), .Names = c("value601", "value602", "value603",
> "value604", "value605", "value606", "value607", "value608", "value609",
> "value610", "value611", "value612"), row.names = c("1", "2",
> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] replace items in vector with character based on logical operator

2016-11-12 Thread Adrian Johnson
Hi group,

I have a vector of numeric items and I want to replace based on
logical operator (> or <)  with 'up', 'down' or 'nochange'

The way I am doing works sometimes and does not work sometime. I dont
understand the problem. In this example, that works for condition DN
first, gets over-written by UP and then by NC.


 I appreciate your help.
Thanks
Adrian

In the example below (dput code given below).

qt = quantile(kx)
kx[kx <= qt[[2]]] <- 'DN'
kx[kx >=qt [[4]]] <- 'UP'
kx[kx < qt[[4]] | kx > qt[[2]]] <- 'NC'


> qt
   0%   25%   50%   75%  100%
 9.341531  9.995026 10.186305 10.444237 11.013304

> kx[kx <= qt[[2]]] <- 'DN'
> kx
  TCGA-3H-AB3K   TCGA-3H-AB3L   TCGA-3H-AB3M
TCGA-3H-AB3O   TCGA-3H-AB3S   TCGA-3H-AB3T   TCGA-3H-AB3U
 TCGA-3H-AB3X
"11.0133035117116"   "DN" "10.2976687932597"
"10.080008468093" "10.3661039885332"   "DN"
"10.8971723299346" "10.0327245097586"
  TCGA-3U-A98D   TCGA-3U-A98E   TCGA-3U-A98F
TCGA-3U-A98G   TCGA-3U-A98H   TCGA-3U-A98I   TCGA-3U-A98J
 TCGA-LK-A4NW
"10.0094206497379" "10.4816534666287" "10.4317651665439"
"DN" "10.2313364037012"   "DN" "10.1412738417844"
 "DN"
  TCGA-LK-A4NY   TCGA-LK-A4NZ   TCGA-LK-A4O0   TCGA-LK-A4O2
 "10.603941260297" "10.7959493941044" "10.0501324788234" "10.3877479259697"







kx <- structure(c(11.0133035117116, 9.95184228858716, 10.2976687932597,
10.080008468093, 10.3661039885332, 9.34153148077152, 10.8971723299346,
10.0327245097586, 10.0094206497379, 10.4816534666287, 10.4317651665439,
9.57711797674944, 10.2313364037012, 9.39562974544228, 10.1412738417844,
9.80706011783492, 10.603941260297, 10.7959493941044, 10.0501324788234,
10.3877479259697), .Names = c("TCGA-3H-AB3K", "TCGA-3H-AB3L",
"TCGA-3H-AB3M", "TCGA-3H-AB3O", "TCGA-3H-AB3S", "TCGA-3H-AB3T",
"TCGA-3H-AB3U", "TCGA-3H-AB3X", "TCGA-3U-A98D", "TCGA-3U-A98E",
"TCGA-3U-A98F", "TCGA-3U-A98G", "TCGA-3U-A98H", "TCGA-3U-A98I",
"TCGA-3U-A98J", "TCGA-LK-A4NW", "TCGA-LK-A4NY", "TCGA-LK-A4NZ",
"TCGA-LK-A4O0", "TCGA-LK-A4O2"))

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] replace items in vector with character based on logical operator

2016-11-12 Thread Jeff Newmiller
Your goal is fundamentally flawed,  since all elements of a vector must be if 
the same type. 
Create another vector to hold your character information. 

kc <- rep( 'NC', length( kx ) )
kc[ kx <= qt[[2]] ] <- 'DN'
kc[ kx >=qt [[4]] ] <- 'UP'

-- 
Sent from my phone. Please excuse my brevity.

On November 12, 2016 2:25:51 PM PST, Adrian Johnson  
wrote:
>Hi group,
>
>I have a vector of numeric items and I want to replace based on
>logical operator (> or <)  with 'up', 'down' or 'nochange'
>
>The way I am doing works sometimes and does not work sometime. I dont
>understand the problem. In this example, that works for condition DN
>first, gets over-written by UP and then by NC.
>
>
> I appreciate your help.
>Thanks
>Adrian
>
>In the example below (dput code given below).
>
>qt = quantile(kx)
>kx[kx <= qt[[2]]] <- 'DN'
>kx[kx >=qt [[4]]] <- 'UP'
>kx[kx < qt[[4]] | kx > qt[[2]]] <- 'NC'
>
>
>> qt
>   0%   25%   50%   75%  100%
> 9.341531  9.995026 10.186305 10.444237 11.013304
>
>> kx[kx <= qt[[2]]] <- 'DN'
>> kx
>  TCGA-3H-AB3K   TCGA-3H-AB3L   TCGA-3H-AB3M
>TCGA-3H-AB3O   TCGA-3H-AB3S   TCGA-3H-AB3T   TCGA-3H-AB3U
> TCGA-3H-AB3X
>"11.0133035117116"   "DN" "10.2976687932597"
>"10.080008468093" "10.3661039885332"   "DN"
>"10.8971723299346" "10.0327245097586"
>  TCGA-3U-A98D   TCGA-3U-A98E   TCGA-3U-A98F
>TCGA-3U-A98G   TCGA-3U-A98H   TCGA-3U-A98I   TCGA-3U-A98J
> TCGA-LK-A4NW
>"10.0094206497379" "10.4816534666287" "10.4317651665439"
>"DN" "10.2313364037012"   "DN" "10.1412738417844"
> "DN"
>  TCGA-LK-A4NY   TCGA-LK-A4NZ   TCGA-LK-A4O0   TCGA-LK-A4O2
>"10.603941260297" "10.7959493941044" "10.0501324788234"
>"10.3877479259697"
>
>
>
>
>
>
>
>kx <- structure(c(11.0133035117116, 9.95184228858716, 10.2976687932597,
>10.080008468093, 10.3661039885332, 9.34153148077152, 10.8971723299346,
>10.0327245097586, 10.0094206497379, 10.4816534666287, 10.4317651665439,
>9.57711797674944, 10.2313364037012, 9.39562974544228, 10.1412738417844,
>9.80706011783492, 10.603941260297, 10.7959493941044, 10.0501324788234,
>10.3877479259697), .Names = c("TCGA-3H-AB3K", "TCGA-3H-AB3L",
>"TCGA-3H-AB3M", "TCGA-3H-AB3O", "TCGA-3H-AB3S", "TCGA-3H-AB3T",
>"TCGA-3H-AB3U", "TCGA-3H-AB3X", "TCGA-3U-A98D", "TCGA-3U-A98E",
>"TCGA-3U-A98F", "TCGA-3U-A98G", "TCGA-3U-A98H", "TCGA-3U-A98I",
>"TCGA-3U-A98J", "TCGA-LK-A4NW", "TCGA-LK-A4NY", "TCGA-LK-A4NZ",
>"TCGA-LK-A4O0", "TCGA-LK-A4O2"))
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] replace items in vector with character based on logical operator

2016-11-12 Thread William Dunlap via R-help
Your first replacement in kx changed it to a character vector and
comparisons
of character strings given different results than comparisons of numbers

> kx <- 1:10
> qt <- quantile(kx)
> kx[kx <= qt[2]] <- "DN"
> kx
 [1] "DN" "DN" "DN" "4"  "5"  "6"  "7"  "8"  "9"  "10"
> "10" < "6"
[1] TRUE
>
> # compare to
> kx <- 1:10
> code <- character(length(kx))
> qt <- quantile(kx)
> code[kx <= qt[2]] <- "DN"
> code
 [1] "DN" "DN" "DN" ""   ""   ""   ""   ""   ""   ""
> code[kx >= qt[4]] <- "DN"
> code
 [1] "DN" "DN" "DN" ""   ""   ""   ""   "DN" "DN" "DN"


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Nov 12, 2016 at 2:25 PM, Adrian Johnson 
wrote:

> Hi group,
>
> I have a vector of numeric items and I want to replace based on
> logical operator (> or <)  with 'up', 'down' or 'nochange'
>
> The way I am doing works sometimes and does not work sometime. I dont
> understand the problem. In this example, that works for condition DN
> first, gets over-written by UP and then by NC.
>
>
>  I appreciate your help.
> Thanks
> Adrian
>
> In the example below (dput code given below).
>
> qt = quantile(kx)
> kx[kx <= qt[[2]]] <- 'DN'
> kx[kx >=qt [[4]]] <- 'UP'
> kx[kx < qt[[4]] | kx > qt[[2]]] <- 'NC'
>
>
> > qt
>0%   25%   50%   75%  100%
>  9.341531  9.995026 10.186305 10.444237 11.013304
>
> > kx[kx <= qt[[2]]] <- 'DN'
> > kx
>   TCGA-3H-AB3K   TCGA-3H-AB3L   TCGA-3H-AB3M
> TCGA-3H-AB3O   TCGA-3H-AB3S   TCGA-3H-AB3T   TCGA-3H-AB3U
>  TCGA-3H-AB3X
> "11.0133035117116"   "DN" "10.2976687932597"
> "10.080008468093" "10.3661039885332"   "DN"
> "10.8971723299346" "10.0327245097586"
>   TCGA-3U-A98D   TCGA-3U-A98E   TCGA-3U-A98F
> TCGA-3U-A98G   TCGA-3U-A98H   TCGA-3U-A98I   TCGA-3U-A98J
>  TCGA-LK-A4NW
> "10.0094206497379" "10.4816534666287" "10.4317651665439"
> "DN" "10.2313364037012"   "DN" "10.1412738417844"
>  "DN"
>   TCGA-LK-A4NY   TCGA-LK-A4NZ   TCGA-LK-A4O0   TCGA-LK-A4O2
>  "10.603941260297" "10.7959493941044" "10.0501324788234" "10.3877479259697"
>
>
>
>
>
>
>
> kx <- structure(c(11.0133035117116, 9.95184228858716, 10.2976687932597,
> 10.080008468093, 10.3661039885332, 9.34153148077152, 10.8971723299346,
> 10.0327245097586, 10.0094206497379, 10.4816534666287, 10.4317651665439,
> 9.57711797674944, 10.2313364037012, 9.39562974544228, 10.1412738417844,
> 9.80706011783492, 10.603941260297, 10.7959493941044, 10.0501324788234,
> 10.3877479259697), .Names = c("TCGA-3H-AB3K", "TCGA-3H-AB3L",
> "TCGA-3H-AB3M", "TCGA-3H-AB3O", "TCGA-3H-AB3S", "TCGA-3H-AB3T",
> "TCGA-3H-AB3U", "TCGA-3H-AB3X", "TCGA-3U-A98D", "TCGA-3U-A98E",
> "TCGA-3U-A98F", "TCGA-3U-A98G", "TCGA-3U-A98H", "TCGA-3U-A98I",
> "TCGA-3U-A98J", "TCGA-LK-A4NW", "TCGA-LK-A4NY", "TCGA-LK-A4NZ",
> "TCGA-LK-A4O0", "TCGA-LK-A4O2"))
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, :

2016-11-12 Thread greg holly
Dear all;

I am getting the following error message when I run maSigPro package by
using

make.design.matrix commend. I could not figure out why this error happens.
Thanks for your help

Greg

Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,  :
  ‘min’ not meaningful for factors

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, :

2016-11-12 Thread Duncan Murdoch

On 12/11/2016 7:33 PM, greg holly wrote:

Dear all;

I am getting the following error message when I run maSigPro package by
using

make.design.matrix commend. I could not figure out why this error happens.
Thanks for your help

Greg

Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,  :
  ‘min’ not meaningful for factors



You'll need to give a minimal reproducible example (i.e. something 
others can run, but not containing a lot of unnecessary stuff) if you 
want help with this.


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, :

2016-11-12 Thread greg holly
Hi Duncan;


Thanks for this. I used followed command. In command line: blood is the
name of the data file, degree=11 because I have 12-time point. I need to
create the design matrix of dummies (named des_blood) for fitting time
series micorarray gene expression experiments using maSigPro program.


des_blood=make.design.matrix(blood, degree=11)

On Sat, Nov 12, 2016 at 7:54 PM, Duncan Murdoch 
wrote:

> On 12/11/2016 7:33 PM, greg holly wrote:
>
>> Dear all;
>>
>> I am getting the following error message when I run maSigPro package by
>> using
>>
>> make.design.matrix commend. I could not figure out why this error happens.
>> Thanks for your help
>>
>> Greg
>>
>> Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,  :
>>   ‘min’ not meaningful for factors
>>
>>
> You'll need to give a minimal reproducible example (i.e. something others
> can run, but not containing a lot of unnecessary stuff) if you want help
> with this.
>
> Duncan Murdoch
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] value matching %in% for a number pair

2016-11-12 Thread John
Hi,

   We can match one numerical value as follows
> 3 %in% c(4,5)
[1] FALSE
> 3 %in% c(4,5,3)
[1] TRUE

   To see whether value pairs are identical,
> identical(c(3,4), c(3,5))
[1] FALSE
> identical(c(3,4), c(3,4))
[1] TRUE

   Is there any way to test whether “A value pair is in a set of value
pairs”? For example, can we test whether the pair (2,3) is identical to one
of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
   In this case, the answer is yes because the 4th element of S is (2,3).
Is there any simple way to code it? Thanks!

John

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] value matching %in% for a number pair

2016-11-12 Thread Duncan Murdoch

On 12/11/2016 8:36 PM, John wrote:

Hi,

   We can match one numerical value as follows

3 %in% c(4,5)

[1] FALSE

3 %in% c(4,5,3)

[1] TRUE

   To see whether value pairs are identical,

identical(c(3,4), c(3,5))

[1] FALSE

identical(c(3,4), c(3,4))

[1] TRUE

   Is there any way to test whether “A value pair is in a set of value
pairs”? For example, can we test whether the pair (2,3) is identical to one
of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
   In this case, the answer is yes because the 4th element of S is (2,3).
Is there any simple way to code it? Thanks!


You'll have to type a long expression or write your own function for it. 
 Here's one way, if you store your set as a list:


inlist <- function(x, thelist)
  any(sapply(thelist, identical, x))

For example:

> S <- list(c(1, 2), c(4, 3))
> inlist(c(4, 3), S)
[1] TRUE
> inlist(c(3, 4), S)
[1] FALSE

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, :

2016-11-12 Thread Duncan Murdoch

On 12/11/2016 8:14 PM, greg holly wrote:

Hi Duncan;


Thanks for this. I used followed command. In command line: blood is the
name of the data file, degree=11 because I have 12-time point. I need to
create the design matrix of dummies (named des_blood) for fitting time
series micorarray gene expression experiments using maSigPro program.


Who but you can run this?  We don't have "blood".

Duncan Murdoch



des_blood=make.design.matrix(blood, degree=11)


On Sat, Nov 12, 2016 at 7:54 PM, Duncan Murdoch
mailto:murdoch.dun...@gmail.com>> wrote:

On 12/11/2016 7:33 PM, greg holly wrote:

Dear all;

I am getting the following error message when I run maSigPro
package by
using

make.design.matrix commend. I could not figure out why this
error happens.
Thanks for your help

Greg

Error in Summary.factor(c(24L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L,  :
  ‘min’ not meaningful for factors


You'll need to give a minimal reproducible example (i.e. something
others can run, but not containing a lot of unnecessary stuff) if
you want help with this.

Duncan Murdoch




__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] value matching %in% for a number pair

2016-11-12 Thread Jeff Newmiller
This really depends on the way you represent these pairs. Here is some food for 
thought:

p <- matrix( c( 1,2, 4,3, 3,3, 2,3, 4,5 ), byrow=TRUE, ncol=2 )
( 2 %in% p[,1] ) & ( 3 %in% p[,2] ) # (2,3)
( c( 2, 1, 5 ) %in% p[,1] ) & ( c( 3, 2, 5 ) %in% p[,2] ) # (2,3) (1,2) (5,5)

-- 
Sent from my phone. Please excuse my brevity.

On November 12, 2016 5:36:37 PM PST, John  wrote:
>Hi,
>
>   We can match one numerical value as follows
>> 3 %in% c(4,5)
>[1] FALSE
>> 3 %in% c(4,5,3)
>[1] TRUE
>
>   To see whether value pairs are identical,
>> identical(c(3,4), c(3,5))
>[1] FALSE
>> identical(c(3,4), c(3,4))
>[1] TRUE
>
>   Is there any way to test whether “A value pair is in a set of value
>pairs”? For example, can we test whether the pair (2,3) is identical to
>one
>of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
> In this case, the answer is yes because the 4th element of S is (2,3).
>Is there any simple way to code it? Thanks!
>
>John
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] value matching %in% for a number pair

2016-11-12 Thread William Dunlap via R-help
> S <- list(c(1,2), c(4,3), c(3,3), c(2,3), c(4,5))
> list(c(1,2), c(3,4), c(2,3)) %in% S # is in S?
[1]  TRUE FALSE  TRUE
> match(list(c(1,2), c(3,4), c(2,3)), S) # which element of S?
[1]  1 NA  4


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Nov 12, 2016 at 5:36 PM, John  wrote:

> Hi,
>
>We can match one numerical value as follows
> > 3 %in% c(4,5)
> [1] FALSE
> > 3 %in% c(4,5,3)
> [1] TRUE
>
>To see whether value pairs are identical,
> > identical(c(3,4), c(3,5))
> [1] FALSE
> > identical(c(3,4), c(3,4))
> [1] TRUE
>
>Is there any way to test whether “A value pair is in a set of value
> pairs”? For example, can we test whether the pair (2,3) is identical to one
> of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
>In this case, the answer is yes because the 4th element of S is (2,3).
> Is there any simple way to code it? Thanks!
>
> John
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] value matching %in% for a number pair

2016-11-12 Thread Jeff Newmiller
Sorry, that was a fail. Better to think about:

any( 2 == p[,1] & 3 == p[,2] )
v <- matrix( c( 2,3, 1,2, 5,5 ), byrow=TRUE, ncol=2 )
apply( v, 1, function(x) { any( x[1]==p[,1] & x[2]==p[,2] ) } )

-- 
Sent from my phone. Please excuse my brevity.

On November 12, 2016 6:11:13 PM PST, Jeff Newmiller  
wrote:
>This really depends on the way you represent these pairs. Here is some
>food for thought:
>
>p <- matrix( c( 1,2, 4,3, 3,3, 2,3, 4,5 ), byrow=TRUE, ncol=2 )
>( 2 %in% p[,1] ) & ( 3 %in% p[,2] ) # (2,3)
>( c( 2, 1, 5 ) %in% p[,1] ) & ( c( 3, 2, 5 ) %in% p[,2] ) # (2,3) (1,2)
>(5,5)
>
>-- 
>Sent from my phone. Please excuse my brevity.
>
>On November 12, 2016 5:36:37 PM PST, John  wrote:
>>Hi,
>>
>>   We can match one numerical value as follows
>>> 3 %in% c(4,5)
>>[1] FALSE
>>> 3 %in% c(4,5,3)
>>[1] TRUE
>>
>>   To see whether value pairs are identical,
>>> identical(c(3,4), c(3,5))
>>[1] FALSE
>>> identical(c(3,4), c(3,4))
>>[1] TRUE
>>
>>   Is there any way to test whether “A value pair is in a set of value
>>pairs”? For example, can we test whether the pair (2,3) is identical
>to
>>one
>>of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
>> In this case, the answer is yes because the 4th element of S is
>(2,3).
>>Is there any simple way to code it? Thanks!
>>
>>John
>>
>>  [[alternative HTML version deleted]]
>>
>>__
>>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] value matching %in% for a number pair

2016-11-12 Thread Jim Lemon
Hi john,
I don't know whether this breaks any rules, but:

target_pair<-c(3,4)
pair_list<-list(c(1,2),c(3,4),c(5,6))
sapply(pair_list,identical,target_pair)
[1] FALSE  TRUE FALSE

Jim


On Sun, Nov 13, 2016 at 1:32 PM, Jeff Newmiller
 wrote:
> Sorry, that was a fail. Better to think about:
>
> any( 2 == p[,1] & 3 == p[,2] )
> v <- matrix( c( 2,3, 1,2, 5,5 ), byrow=TRUE, ncol=2 )
> apply( v, 1, function(x) { any( x[1]==p[,1] & x[2]==p[,2] ) } )
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On November 12, 2016 6:11:13 PM PST, Jeff Newmiller 
>  wrote:
>>This really depends on the way you represent these pairs. Here is some
>>food for thought:
>>
>>p <- matrix( c( 1,2, 4,3, 3,3, 2,3, 4,5 ), byrow=TRUE, ncol=2 )
>>( 2 %in% p[,1] ) & ( 3 %in% p[,2] ) # (2,3)
>>( c( 2, 1, 5 ) %in% p[,1] ) & ( c( 3, 2, 5 ) %in% p[,2] ) # (2,3) (1,2)
>>(5,5)
>>
>>--
>>Sent from my phone. Please excuse my brevity.
>>
>>On November 12, 2016 5:36:37 PM PST, John  wrote:
>>>Hi,
>>>
>>>   We can match one numerical value as follows
 3 %in% c(4,5)
>>>[1] FALSE
 3 %in% c(4,5,3)
>>>[1] TRUE
>>>
>>>   To see whether value pairs are identical,
 identical(c(3,4), c(3,5))
>>>[1] FALSE
 identical(c(3,4), c(3,4))
>>>[1] TRUE
>>>
>>>   Is there any way to test whether “A value pair is in a set of value
>>>pairs”? For example, can we test whether the pair (2,3) is identical
>>to
>>>one
>>>of the pairs in the set S={(1,2), (4,3), (3,3), (2,3), (4,5)}?
>>> In this case, the answer is yes because the 4th element of S is
>>(2,3).
>>>Is there any simple way to code it? Thanks!
>>>
>>>John
>>>
>>>  [[alternative HTML version deleted]]
>>>
>>>__
>>>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Re: [R] Is this foreach behaviour correct?

2016-11-12 Thread James Hirschorn
I'm still not clear about whether this is a bug in foreach. Should c.Date be 
invoked by foreach with .combine='c'?

On 11/06/2016 07:02 PM, William Dunlap wrote:
Note that in the OP's example c.Date is never invoked.  c.Date is called if 
.combine
calls c rather than if .combine is c:

> library(zoo)
> trace(c.Date, quote(print(sys.call(
Tracing function "c.Date" in package "base"
[1] "c.Date"
> foreach(i=1:10003, .combine=c) %do% { as.Date(i) }
[1] 1 10001 10002 10003
> foreach(i=1:10003, .combine=function(...)c(...)) %do% { as.Date(i) }
Tracing c.Date(...) on entry
eval(expr, envir, enclos)
Tracing c.Date(...) on entry
eval(expr, envir, enclos)
Tracing c.Date(...) on entry
eval(expr, envir, enclos)
[1] "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22"


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Nov 6, 2016 at 2:20 PM, Duncan Murdoch 
mailto:murdoch.dun...@gmail.com>> wrote:
On 06/11/2016 5:02 PM, Jim Lemon wrote:
hi James,
I think you have to have a starting date ("origin") for as.Date to
convert numbers to dates.

That's true with the function in the base package, but the zoo package also has 
an as.Date() function, which defaults the origin to "1970-01-01".  If James is 
using zoo his code would be okay.  If he's not, he would have got an error, so 
I think he must have been.

Duncan Murdoch



Jim

On Sun, Nov 6, 2016 at 12:10 PM, James Hirschorn
mailto:james.hirsch...@hotmail.com>> wrote:
This seemed odd so I wanted to check:

 > x <- foreach(i=1:10100, .combine='c') %do% { as.Date(i) }

yields a numeric vector for x:

 > class(x)
[1] "numeric"

Should it not be a vector of Date?

__
R-help@r-project.org mailing list -- To 
UNSUBSCRIBE and more, see
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-help@r-project.org mailing list -- To 
UNSUBSCRIBE and more, see
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-help@r-project.org mailing list -- To 
UNSUBSCRIBE and more, see
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.



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.