On 2020-04-03 07:39 +1100, Jim Lemon wrote:
|
| Hi Rasmus,
| Very nice. The R help list is a bit like a
| quiz show where the contestants must
| balance the alacrity with which they press
| their buttons with the confidence that they
| have the correct answer. A slow motion game
| of wits in
On 2020-04-01 15:33 +1100, Jim Lemon wrote:
> Hi Nevil,
> It's a nasty piece of work, but:
Hi! How about this one:
data <- c(rep(1:4, times=3), 2, 1, 3, 2)
dimnames <- list(NULL, c("x", "y", "z", "k"))
ncol <- length(data)/4
M <- matrix(data=data, nrow=ncol, ncol=ncol, dimnames=d
Hi Rasmus,
Very nice. The R help list is a bit like a quiz show where the
contestants must balance the alacrity with which they press their
buttons with the confidence that they have the correct answer. A slow
motion game of wits in which the prizes are self-awarded.
Jim
On Fri, Apr 3, 2020 at 7:
Hi Nevil,
It's a nasty piece of work, but:
M<-matrix(c(1,2,3,4,1,2,3,4,1,2,3,4,2,1,3,2),4,4,
dimnames = list(NULL, c("x", "y", "z","k")))
M
reprow<-function(x)
return(matrix(rep(x,x[length(x)]),nrow=x[length(x)],byrow=TRUE))
toseq<-function(x) return(1:x)
j<-unlist(sapply(M[,"k"],toseq))
Mlist<-a
OK sorted - hope these postings might help someone else
Any even faster options would be appreciated still
#seq() does not work but sequence() does
print("rep and sequence")
print(system.time({
j<-NULL
MOut<-NULL
MOut<-M[rep(1:nrow(M), times = M[,4]), ]
j<-sequence(M[,4])
MOut<-cbind(M
Well,
I found a way to do it partly using rep(), and one loop that makes it 10x
or more faster however would still be good to do without the loop at all
matrix made slightly beigger (1 rows):
M<-matrix(c(1:3
), 1,3)
M<-cbind(M,sample(1:5,size = 1,replace = T))
#Print(M)
#Create mat
False premise: rep works fine
Mout2 <- cbind(M[ rep(seq.int(nrow(M)),M[,"k"]),
c("x","y","z")],unlist(lapply(M[,"k"],seq.int)))
On March 31, 2020 6:18:37 PM PDT, nevil amos wrote:
>Hi
>
>I can achieve this using two for loops but it is slow I need to do
>this on
>many matrices with tens of mil
Hi
I can achieve this using two for loops but it is slow I need to do this on
many matrices with tens of millions of rows of x,y,z and k
What is a faster method to achieve this, I cannot use rep as j changes in
each row of the new matrix
###
M<-matrix(
Thanks Petr. Really appreciated!
Many thanks,
Eric
-Original Message-
From: PIKAL Petr [mailto:petr.pi...@precheza.cz]
Sent: 03 November 2017 07:54
To: Eric Pueyo; r-help@r-project.org
Subject: RE: [R] repeat a function
Hi
Well, I am not an expert in this field so I cannot comment
om: eric.pu...@avivainvestors.com [mailto:eric.pu...@avivainvestors.com]
> Sent: Thursday, November 2, 2017 5:54 PM
> To: PIKAL Petr ; r-help@r-project.org
> Subject: RE: [R] repeat a function
>
> Hi Petr,
>
> Many thanks for your response.
>
> Basically I want to create a pr
j,sep = ""),"1"] <<- ProbUP(a,j,dt)
prb[paste(j,sep = ""),"0"] <<- ProbMID(a,j,dt)
prb[paste(j,sep = ""),"-1"] <<- ProbDWN(a,j,dt)
prb[paste(-j,sep = ""),"1"] <<- ProbUP(a,-j,d
easily transform it to
> matrix by setting dim argument to it.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> > eric.pu...@avivainvestors.com
> > Sent: Wednesday, November 1, 2017 1:31
s
Petr
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> eric.pu...@avivainvestors.com
> Sent: Wednesday, November 1, 2017 1:31 PM
> To: r-help@r-project.org
> Subject: [R] repeat a function
>
> I want to populate the matrix prb t
I want to populate the matrix prb through the function HWMProb <- function
(a,j,dt) that encapsulates different functions (please see code below), using
j= 0:2 for each j.
It only populates prb if I specify each function independently in the global
environment and then run the loop with the iF
> On Feb 25, 2017, at 4:36 PM, Ashta wrote:
>
> Thank you so much David!
>
> But if all element of a group has '-' did not work. In this case year
> 2006 an example
> If all values of flag are '-' within year then I wan to set as N
I don't see the difficulty (and your example did not provi
Thank you so much David!
But if all element of a group has '-' did not work. In this case year
2006 an example
If all values of flag are '-' within year then I wan to set as N
dat=read.table(text = "Year month flag
2001 1 Z
2001 2 -
2001 4 X
2002 1 Z
2002 2 -
2003 1 -
2003 2 Z
> On Feb 25, 2017, at 10:45 AM, Ashta wrote:
>
> Thank you David.
> is it not possible to sort it by year and flag so that we can make '-'
> in the second row ? like this for that particular year.
>
> 2003 2 Z
> 2003 1 -
>
I was a bit surprised by the results of htis since I had
Thank you David.
is it not possible to sort it by year and flag so that we can make '-'
in the second row ? like this for that particular year.
2003 2 Z
2003 1 -
On Sat, Feb 25, 2017 at 12:14 PM, David Winsemius
wrote:
>
>> On Feb 25, 2017, at 8:09 AM, Ashta wrote:
>>
>> I ha
> On Feb 25, 2017, at 8:09 AM, Ashta wrote:
>
> I have a data set and I want to repeat a column value based on other
> column value,
>
> my data look like
>
> read.table(text = "Year month flag
> 2001 1 Z
> 2001 2 -
> 2001 4 X
> 2002 1 Z
> 2002 2 -
> 2003 1 -
> 2003 2 Z
> 2004 2
I have a data set and I want to repeat a column value based on other
column value,
my data look like
read.table(text = "Year month flag
2001 1 Z
2001 2 -
2001 4 X
2002 1 Z
2002 2 -
2003 1 -
2003 2 Z
2004 2 Z
2005 3 Z
2005 2 -
2005 3 -", header = TRUE)
Within year If flag
Not sure it would be any smarter, but what about:
a <- c(5.78, 5.79,5.86)
n <- 10
matrix(rep(a,each=n), nrow=n)
That way, it would be easy to build a function with 'a' and 'n' as
arguments.
HTH,
Ivan
--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA
Dear r-users,
I have a set of numbers that I would like to repeat for let say 10 times
and each number is repeated by vertically.
I tried this:
a <- c(5.78, 5.79,5.86)
tran_a <- t(matrix(rep.int(a, 10),3))
dput(tran_a)
structure(c(5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78,
5.78, 5.7
2015 2:34 PM
> To: r-help@r-project.org
> Subject: [R] Repeat elements of character vector
>
> I have a vector of several character elements:
> v1 <- c("a", "b", "c")
>
> I want each of these elements to be repeated n times and the number of
&g
Hi,
Take a look at the argument "each" from rep().
You could do that (there might be something shorter):
paste(rep(v1,each=3), 1:3, sep="_")
HTH,
Ivan
--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26
> paste(rep(v1, each=3), 1:3, sep="_")
[1] "a_1" "a_2" "a_3" "b_1" "b_2" "b_3" "c_1" "c_2" "c_3"
>
Is this what you are looking for? I hope this helps.
Chel Hee Lee
On 1/30/2015 7:34 AM, Knut Hansen wrote:
I have a vector of several character elements:
v1 <- c("a", "b", "c")
I want each of t
I have a vector of several character elements:
v1 <- c("a", "b", "c")
I want each of these elements to be repeated n times and the number of the
repetition added as part of the element text, hence rep() will not work. For
n=3 the result would be:
v2 <- c("a_1", "a_2", "a_3", "b_1", "b_2", "b_3",
Hi,
Try:
Please use ?dput() to show the example dataset:
dat <- structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), Y = c(555L,
345L, 456L, 552L, 342L, 452L, 555L, 345L, 456L, 552L, 342L, 452L,
562L, 352L, 463L, 582L, 342L, 483
, October 14, 2013 7:47 AM
To: r-help@r-project.org
Subject: [R] repeat a linear regression model
Hello,
I'd like to repeat a linear regression model for groups of rows that are
identified by an ID number.
My table is like this:
ID Y X1 X2 X3 X4
1 555 111
Hello,
I'd like to repeat a linear regression model for groups of rows that are
identified by an ID number.
My table is like this:
ID Y X1 X2 X3 X4
1 555 111 222 333 456
1 345 234 445 543 33
1 456 353 453 456
Hi,
I'm trying to write a code (see below) to randomly resample measurements of
one variable (say here the variable "counts" in the data frame "dat") with
different resampled subsample sizes.
The code works fine for a single resampled subsample size (in the code below
= 10).
I then tried to genera
- Original Message -
From: Sarah Haas
To: r-help@r-project.org
Cc:
Sent: Thursday, December 13, 2012 9:15 AM
Subject: [R] Repeat elements of matrix based on vector counts
I have two dataframes (df) that share a column header ("plot.id"). In the
1st df, "plot.id" recor
Hello,
Something like this?
rep(df2$load, table(df1$plot.id))
Hope this helps,
Rui Barradas
Em 13-12-2012 14:15, Sarah Haas escreveu:
I have two dataframes (df) that share a column header ("plot.id"). In the
1st df, "plot.id" records are repeated a variable number of times based on
the numb
Hi Sarah,
If I understand your requirements correctly, the easiest thing to do
is approach it from a different direction:
df3a <- merge(df1, df2)
But you can also use rep for this simple example because plot.id in
df2 is sorted:
nindex <- table(df1$plot.id)
df3b <- df2[rep(1:length(nindex), times
I have two dataframes (df) that share a column header ("plot.id"). In the
1st df, "plot.id" records are repeated a variable number of times based on
the number of trees monitored within each plot. The 2nd df only has a
single record for each "plot.id", and contains a variable named "load" that
is
Hi Petr
Thanks for reply.
On 24 October 2012 07:26, PIKAL Petr [via R] <
ml-node+s789695n464726...@n4.nabble.com> wrote:
> Hi
>
> It is a piece of my code. At this, i create a matrix(deltab) with each
column is a binomial, but in there are several NAs, and i must restart
the cycle the number o
Hi
>
> Hi
>
> I want help for "repeat" because it takes a long time
>
> repeat{
> for (i in 1:n){
> probb[i]=sum(Wc[z[,j]>=yb[i]])
> }
> deltab[,b]=rbinom(n,1,probb)
> if(length(which(is.na(deltab[,b])==T))==0){break}
> }
>
> This code works but takes much computation time.
What is this code
Hi
I want help for "repeat" because it takes a long time
repeat{
for (i in 1:n){
probb[i]=sum(Wc[z[,j]>=yb[i]])
}
deltab[,b]=rbinom(n,1,probb)
if(length(which(is.na(deltab[,b])==T))==0){break}
}
This code works but takes much computation time.
Anyone could help me to find a solution to take a
a <- matrix(1:8, 2, 4, byrow=TRUE)
b<-t(a)
r<-rep(b,5) # can insert anything for 5
matrix(r,ncol=dim(a)[2],byrow=T)
[,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
[3,]1234
[4,]5678
[5,]1234
[6,]5678
Hi
what about
rbind(a,a)
[,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
[3,]1234
[4,]5678
Regards
Petr
>
> > a <- matrix(1:8, 2, 4, byrow=TRUE)
> > a
> [,1] [,2] [,3] [,4]
> [1,]1234
> [2,]5678
>
Yes, integer vector indexing. You haven't provided R code to work with so I
will just refer you to read the pdf "An Introduction to R" included with most R
installations for more details.
---
Jeff Newmiller
> a <- matrix(1:8, 2, 4, byrow=TRUE)
> a
[,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
> a[c(1,2,1,2),]
[,1] [,2] [,3] [,4]
[1,]1234
[2,]5678
[3,]1234
[4,]5678
>
On Wed, Apr 25, 2012 at 8:32 PM, Rebec
Hi,
If I have a matrix like
1 2 3 4
5 6 7 8,
how can I repeat two rows as whole, to be like
1 2 3 4
5 6 7 8
1 2 3 4
5 6 7 8?
Since I have more two rows in a matrix and I need to repeat many times, I
wonder whether there is a convenient command to do so.
Thanks!
[[alte
No problem. Glad it worked for you.
Michael
On Mon, Jan 30, 2012 at 12:05 PM, pabears wrote:
> michael,
>
> i don't know what happened, i was reading up on ?lapply(), i was up really
> late, and somehow it didn't seem to take, but i tried it again this morning
> and it worked like a charm...
michael,
i don't know what happened, i was reading up on ?lapply(), i was up really
late, and somehow it didn't seem to take, but i tried it again this morning
and it worked like a charm.(sorry about the ellipses, i was just
being lazy/unclear).
that's great, thanks, this is a great h
lapply() takes a function in its second argument, but that is not what
you passed it. Also, there's no such construct in R as "."
What happens with the code I gave you?
Michael
On Sun, Jan 29, 2012 at 4:28 PM, pabears wrote:
> didn't seem to quite work:
>
> i tried different subsetting.
didn't seem to quite work:
i tried different subsetting.
lapply(nestedseasonlower, nested(nestedseason,.)
are there any functions that can repeat a function while "counting" each
iteration of the repeated function? (n=1, n=2, n=3)
thanks
--
View this message in context:
http://r.7
?lapply
Perhaps (untested):
lapply(listofmatrices, nested, method="binmatnest2")
Michael
On Fri, Jan 27, 2012 at 3:19 PM, pabears wrote:
> hi all.
>
> perhaps someone can help me with subsetting here
>
> i'm trying to use the nested() function in the bipartite package. my
> proble
hi all.
perhaps someone can help me with subsetting here
i'm trying to use the nested() function in the bipartite package. my
problem is that i have a list of 10,000 matrices and i want the output to be
a vector of the nested() function on each of the 10,000 matrices (so i can
use th
If you want to generate truncated distributions, package 'tmvtnorm' can
help you out.
Regards,
Denes
>>
>> Dear all,
>>
>> I know there have been various questions posted over the years about
> loops
>> but I'm afraid that I'm still stuck. I am using Windows XP and R 2.9.2.
>> I am generati
Hi
I may be completely off track without knowing mnormt package but what
about using while loop for counting rows in "correct" datamat.
#first set your matrix
datamat <-
rmnorm(n=1500,mean=c(mean(sanad[,1]),mean(sanad[,2]),mean(sanad[,3])),varcov=covmat)
#get rid of out of spec values
datamat
Dear all,
I know there have been various questions posted over the years about loops but
I'm afraid that I'm still stuck. I am using Windows XP and R 2.9.2.
I am generating some data using the multivariate normal distribution (within
the 'mnormt' package). [The numerical values of sanad and cov
Or you could take advantage of R's automatic recycling:
> x$b <- rep(1:3, length=nrow(x))
> x
a b
1 1 1
2 2 2
3 3 3
4 4 1
5 5 2
6 6 3
7 7 1
8 8 2
9 9 3
10 10 1
Thanks for providing a simple reproducible example.
Sarah
On Wed, Jul 20, 2011 at 6:20 PM, Dimitri Liakhovitski
Never mind - found it:
x<-data.frame(a=1:10)
x$b<-rep(1:3,nrow(x)%/%3,len=nrow(x))
Dimitri
On Wed, Jul 20, 2011 at 6:15 PM, Dimitri Liakhovitski
wrote:
> Apologies, for a very simple question. I forgot how to do it -
> although I remember reading about getting a warning in such a
> situation.
>
Apologies, for a very simple question. I forgot how to do it -
although I remember reading about getting a warning in such a
situation.
I have a data frame. It happens to be 10 rows but it could be 11 or 3 or 13...
x<-data.frame(a=1:10)
I need to add variable "b" that is a sequence of 1:3 - repeat
See ?aperm for changing the dimensions afterwards.
Uwe Ligges
On 08.03.2011 10:14, Folkes, Michael wrote:
Hello all,
I'm working with a matrix that will have varying dimensions. It will populate
an array such that the number of matrix columns will determine the number of
3rd dimension level
Hello all,
I'm working with a matrix that will have varying dimensions. It will populate
an array such that the number of matrix columns will determine the number of
3rd dimension levels of the array. Rows will be the same for both. For this
example lets say the array will have 2 columns, but
Hi Laura,
I'm a little weak on my use of connections, but I wonder if something
like this would not be a better option. As I understand it, using
write.table() with append = TRUE is a slow way to many lines to a
file.
## create a writable connection to a file
gt <- file("bootstrap_results.txt",
Hi Laura,
On 11/30/2010 9:57 AM, Laura Bonnett wrote:
Dear all,
I am using R version 2.9.2 in Windows.
I would like to output the results of a function I have written to a .txt
file. I know that I can do this by using the code
write.table(boothd(10),"boothd10.txt",sep="\t",append=TRUE) etc.
Try using a connection:
output <- file('boothd10.txt", 'w')
write.table(boothd(10), output, sep = '\t', col.names = FALSE)
close(output)
On Tue, Nov 30, 2010 at 9:57 AM, Laura Bonnett wrote:
> Dear all,
>
> I am using R version 2.9.2 in Windows.
>
> I would like to output the results of a
Dear all,
I am using R version 2.9.2 in Windows.
I would like to output the results of a function I have written to a .txt
file. I know that I can do this by using the code
write.table(boothd(10),"boothd10.txt",sep="\t",append=TRUE) etc. However, I
would like to bootstrap my function 'boothd' s
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Michael Bedward
> Sent: Wednesday, September 29, 2010 5:34 PM
> To: Michael Larkin; Rhelp
> Subject: Re: [R] repeat a function
>
> On 30 September 20
On 30 September 2010 02:48, Michael Larkin wrote:
> >
> > testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ] )
>
> I can't seem to get it to work. I keep getting the error message of
> "undefined columns selected"
>
> Any advice?
I'd need to know the dimensions of your matrix
Hi Michael
testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ] )
testdat will then be a matrix of 8 x 50 = 400 rows where each lot of 8
is a sample.
Alternatively you can do...
testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ],
simplify=FALSE )
Now testdat
I have R randomly sampling my array made up of 2 columns of data. Here is
my code randomly sampling 5 different rows from my dataset to create a new
dataset of 8 rows of data:
testdat<-growth[sample(5,8,replace=T),]
Now I want to tell R to repeat this function 50 times and give me the
On Wed, Aug 25, 2010 at 11:18 AM, skan wrote:
>
> # duplicated / na.locf doesn't work
> it says Error in fix.by(by.x, x) : 'by' must specify valid column(s)
>
> if I use ifelse instead of ifelse.zoo it works but it gives me a non zoo
> vector.
> Myabe is because my zoo version is older.
>
They
# duplicated / na.locf doesn't work
it says Error in fix.by(by.x, x) : 'by' must specify valid column(s)
if I use ifelse instead of ifelse.zoo it works but it gives me a non zoo
vector.
Myabe is because my zoo version is older.
cheers
--
View this message in context:
http://r.789695.n4.nabbl
On Wed, Aug 25, 2010 at 9:48 AM, skan wrote:
>
> thanks
> I'll try them,
>
> Why do you use the brackets in zz[] ?
So it stays a zoo object with the same index. We are only replacing
the data part.
__
R-help@r-project.org mailing list
https://stat.et
thanks
I'll try them,
Why do you use the brackets in zz[] ?
--
View this message in context:
http://r.789695.n4.nabble.com/Repeat-the-first-day-data-through-all-the-day-Zoo-tp2338069p2338266.html
Sent from the R help mailing list archive at Nabble.com.
___
On Wed, Aug 25, 2010 at 7:43 AM, skan wrote:
>
> down vote favorite
>
>
> Hello
>
> I have a zoo series. It lasts 10 years and its frequency is 15min.
>
> I'd like to get a new zoo series (or vector) with the same number of
> elements, whith each element equal to the first element of the day. Th
On Wed, Aug 25, 2010 at 7:56 AM, Gabor Grothendieck
wrote:
> On Wed, Aug 25, 2010 at 7:43 AM, skan wrote:
>> I have a zoo series. It lasts 10 years and its frequency is 15min.
>>
>> I'd like to get a new zoo series (or vector) with the same number of
>> elements, whith each element equal to the f
On Wed, Aug 25, 2010 at 7:43 AM, skan wrote:
> I have a zoo series. It lasts 10 years and its frequency is 15min.
>
> I'd like to get a new zoo series (or vector) with the same number of
> elements, whith each element equal to the first element of the day. That's,
> The first element everyday is r
down vote favorite
Hello
I have a zoo series. It lasts 10 years and its frequency is 15min.
I'd like to get a new zoo series (or vector) with the same number of
elements, whith each element equal to the first element of the day. That's,
The first element everyday is repeated througho
Hi all,
after browsing the archives for hours I'm still not sure about the proper
analysis for my dataset.
I subjected each of about 50 critters (about 10 each in 5 distinct
populations) to 4 consecutive treatments (exposure to increasing
concentrations), with one measurement per treatment and
For each variable x, y and z I would like to run the same set of
commands. I have tried
for (n in FICB[,"calct30"], FICB[, "calct60]") {
FICB[,"temp"] <- format([n],digits=2)
etc
}
How do I do this correctly?
__
R-help@r-project.org mailing list
https:
Uli Kleinwechter <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> Hello,
>
> I have written a small script to read a dataset, compute some basic
> descriptives and write them to a file (see below). The variable
> "maizeseedcash" of which the statistics are calculated is contained
> in th
Hello,
I have written a small script to read a dataset, compute some basic
descriptives and write them to a file (see below). The variable
"maizeseedcash" of which the statistics are calculated is contained in
the data frame agr_inputs. My question is whether there is a way to make
R compute t
76 matches
Mail list logo