[R] How to stop as.integer removing dimenions

2017-02-23 Thread Thomas Chesney
I have: net1 <- array(0, dim=c(5,5)) str(net1) num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ... and what I want is: str(net1) int [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ... Neither of the following work: net1 <- as.integer(net1, drop=FALSE) net1 <- as.integer(net1, dim=c(5,5)) Can someone please help? Tha

[R] Vectorization in a random order

2016-11-10 Thread Thomas Chesney
Is there a way to use vectorization where the elements are evaluated in a random order? For instance, if the code is to be run on each row in a matrix of length nBuy the following will do the job for (b in sample(1:nBuy,nBuy, replace=FALSE)){ } but apply(nBuyMat, 1, function(x)) will be run

[R] The equivalent of which() when accessing slots in an object

2016-10-31 Thread Thomas Chesney
o search for this I just keep finding info on ls() and similar functions. Thank you Thomas Chesney http://www.nottingham.ac.uk/~liztc/Personal/index.html This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this messa

Re: [R] Increment certain values in a vector

2015-10-01 Thread Thomas Chesney
gents[sel] + 1 The code can be different if agent or agents are objects like matrix or array. Actually from the code xxx$yyy I presume it is data frame or list. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas > Chesne

[R] Increment certain values in a vector

2015-10-01 Thread Thomas Chesney
How can I manipulate values of only certain entries in a vector, based on what the existing values are? So for instance if I want to add one to each of the following values, or multiply them by a specific factor: agents[which(agent$membership == 1)] how would I do this please? If there was ju

[R] Counting occurrences of a set of values

2015-09-10 Thread Thomas Chesney
Can anyone suggest a way of counting how frequently sets of values occurs in a data frame? Like table() only with sets. So for a dataset: V1, V2, V3 1, 2, 1 1, 3, 2 1, 2, 1 1, 1, 1 The output would be something like: 1,2,1: 2 1,3,2: 1 1,1,1: 1 Thank you, Thomas Chesney This message and

Re: [R] Unordered combinations with repetition

2015-06-09 Thread Thomas Chesney
Thank you Nicholas. I've found that Urnsamples in the prob package does it too: urnsamples(1:2, size = 2, replace = TRUE, ordered = FALSE) Thomas From: WRAY NICHOLAS [nicholas.w...@ntlworld.com] Sent: Tuesday, June 09, 2015 10:52 AM To: Thomas Chesn

[R] Unordered combinations with repetition

2015-06-09 Thread Thomas Chesney
Does anyone know of a function that will return all unordered combinations of n elements from a list with repetition? The combs function in caTools will do this without repetition: combs(1:2, 2) [,1] [,2] [1,]12 What I'd like is: 1 1 1 2 2 2 Thank you, Thomas Chesney

[R] Adding columns to a 2D vector

2015-06-03 Thread Thomas Chesney
ot;dimnames")=List of 2 ..$ : NULL ..$ : NULL Thank you, Thomas Chesney This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Plea

Re: [R] pairwise.t.test

2015-02-10 Thread Thomas Chesney
Thank you! From: peter dalgaard [pda...@gmail.com] Sent: Tuesday, February 10, 2015 12:05 PM To: Thomas Chesney Cc: r-help@r-project.org Subject: Re: [R] pairwise.t.test On 10 Feb 2015, at 11:45 , Thomas Chesney wrote: > I'm using pairwise.t.tes

[R] pairwise.t.test

2015-02-10 Thread Thomas Chesney
quot;) I thought the above code would run exactly the same test on Groups 1 and 2, regardless of how many groups are in the dataset. Can anyone explain what's going on? Thank you, Thomas Chesney This message and any attachment are intended solely for the addressee and may contain confiden

Re: [R] For loop indicies

2011-12-12 Thread Thomas Chesney
m...@yahoo.de] Sent: Monday, December 12, 2011 11:59 AM To: Thomas Chesney Cc: r-help@r-project.org Subject: Re: [R] For loop indicies You may want to check how your loop "misses out" the zero: C <- 5 for (i in 0:C) print(i) ## gives me [1] 0 [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 Regards

[R] For loop indicies

2011-12-12 Thread Thomas Chesney
I would like to run a for loop with an index going from 0 to 499 but the following seems to miss out the first value: C <- 499 for (i in 0:C) The alternative is: C <- 500 for (i in 1:C) { #Then every time I use i, I replace it with i-1 } Is this a good way to do it or is tere a better way? Th

Re: [R] arules package intsallation

2011-12-07 Thread Thomas Chesney
From: Prof Brian Ripley [rip...@stats.ox.ac.uk] Sent: Wednesday, December 07, 2011 10:45 AM To: Thomas Chesney Cc: r-help@r-project.org Subject: Re: [R] arules package intsallation On Wed, 7 Dec 2011, Thomas Chesney wrote: > I'm using R versio

[R] arules package intsallation

2011-12-07 Thread Thomas Chesney
I'm using R version 2.13.0 (2011-04-13) on Mac OS X and I get the following error message with library(arules): Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det Error in dyn.load(fil

[R] Automatic Recoding

2011-09-01 Thread Thomas Chesney
I have a text file full of numbers (it's a edgelist for a graph) and I would like to recode the numbers as they are way too big to work with. So for instance the following: 6765290986671000198767829 676529098667100867672856227 67652909866791098726278 67652909866798928373 10928373

[R] Max within groups

2011-07-16 Thread Thomas Chesney
I know there's a really easy way to do this but I just can't track it down. I experimented with various apply functions but couldn't get it quite right. I have a matrix like this: 1, 16 1, 23 1, 21 1, 6 1, 25 2, 4 2, 17 2, 45 2, 11 2, 20 and I'd like to find the max value in Column 2 (or the in