Re: [R] Create matrix with variable number of columns AND CREATE NAMES FOR THE COLUMNS

2024-07-01 Thread Heinz Tuechler via R-help
Sorkin, John wrote/hat geschrieben on/am 01.07.2024 17:54: #I am trying to write code that will create a matrix with a variable number of columns where the #number of columns is 1+Grps #I can do this: NSims <- 4 Grps <- 5 DiffMeans <- matrix(nrow=NSims,ncol=1+Grps) DiffMeans #I have a problem w

Re: [R] Create matrix with variable number of columns AND CREATE NAMES FOR THE COLUMNS

2024-07-01 Thread Jeff Newmiller via R-help
I think you should reconsider your goal. Matrices must have all elements of the same type, and in this case you seem to be trying to mix a number of something (integer) with mean values (double). This would normally be stored together in a data frame or separately in a vector for counts and a ma

Re: [R] Create matrix with variable number of columns AND CREATE NAMES FOR THE COLUMNS

2024-07-01 Thread Rui Barradas
Às 16:54 de 01/07/2024, Sorkin, John escreveu: #I am trying to write code that will create a matrix with a variable number of columns where the #number of columns is 1+Grps #I can do this: NSims <- 4 Grps <- 5 DiffMeans <- matrix(nrow=NSims,ncol=1+Grps) DiffMeans #I have a problem when I try to

Re: [R] Create matrix with variable number of columns AND CREATE NAMES FOR THE COLUMNS

2024-07-01 Thread Rui Barradas
Às 16:54 de 01/07/2024, Sorkin, John escreveu: #I am trying to write code that will create a matrix with a variable number of columns where the #number of columns is 1+Grps #I can do this: NSims <- 4 Grps <- 5 DiffMeans <- matrix(nrow=NSims,ncol=1+Grps) DiffMeans #I have a problem when I try to

Re: [R] Create matrix with variable number of columns AND CREATE NAMES FOR THE COLUMNS

2024-07-01 Thread Ebert,Timothy Aaron
NSims <- 4 Grps <- 5 DiffMeans <- matrix(nrow=NSims,ncol=1+Grps) DiffMeans #I have a problem when I try to name the columns of the matrix. I want the first column to be NSims, #and the other columns to be something like Value1, Value2, . . . Valuen where N=Grps Colnames <- as.vector("NSims") num

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread avi.e.gross
quot;Smith" "Smith" "Smith" "Smith" "Jones" "Jones" "Jones" "Gunter" If that remains unclear, I am doing something wrong today. It is nice to see alternatives but some people just want one answer. Read my first mes

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Bert Gunter
"If you want a much more compact solution that handles arbitrary pairs of "what to copy", number_of_copies, you can write a function that evaluates two arguments at a time or takes two vectors as arguments like this one I wrote quickly and crudely:" Please! -- The "times" argument of rep can be a

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread avi.e.gross
For the particular example you asked for, consider the "each" you can use with rep() rep(1:13, each=84) This is what it does for a shorter version of 4 each: > rep(1:13, each=4) [1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Ebert,Timothy Aaron
Bert Gunter Sent: Thursday, June 13, 2024 9:13 PM To: Ebert,Timothy Aaron Cc: Francesca PANCOTTO ; r-help@r-project.org Subject: Re: [R] Create a numeric series in an efficient way [External Email] Nope. She would have wanted the 'each' argument = 84. See ?rep. -- Bert On Thu, Jun 13,

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Bert Gunter
t; The second line sorts, but that may not be needed depending on > application. The object class is also different in the sorted solution. > > Tim > -Original Message- > From: R-help On Behalf Of Francesca > PANCOTTO via R-help > Sent: Thursday, June 13, 2024 2:22 PM

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Ebert,Timothy Aaron
rom: R-help On Behalf Of Francesca PANCOTTO via R-help Sent: Thursday, June 13, 2024 2:22 PM To: r-help@r-project.org Subject: Re: [R] Create a numeric series in an efficient way [External Email] I apologize, I solved the problem, sorry for that. f. Il giorno gio 13 giu 2024 alle ore 16:42 Fra

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Francesca PANCOTTO via R-help
I apologize, I solved the problem, sorry for that. f. Il giorno gio 13 giu 2024 alle ore 16:42 Francesca PANCOTTO < francesca.panco...@unimore.it> ha scritto: > Dear Contributors > I am trying to create a numeric series with repeated numbers, not > difficult task, but I do not seem to find an e

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Shu Fai Cheung
Dear Bert, Many thanks for your suggestion! I am reading the section to understand more about this topic. It is highly relevant to what I plan to work on. Regards, Shu Fai On Thu, Oct 26, 2023 at 5:38 AM Bert Gunter wrote: > > As you seem to have a need for this sort of capability (e.g. bquote)

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Bert Gunter
As you seem to have a need for this sort of capability (e.g. bquote), see Section 6: "Computing on the Language" in the R Language Definition manual. Actually, if you are interested in a concise (albeit dense) overview of the R Language, you might consider going through the whole manual. Cheers, B

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Shu Fai Cheung
Dear Iris, Many many thanks! This is exactly what I need! I have never heard about bquote(). This function will also be useful to me on other occasions. I still have a lot to learn about the R language ... Regards, Shu Fai On Wed, Oct 25, 2023 at 5:24 PM Iris Simmons wrote: > > You can try ei

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Iris Simmons
You can try either of these: expr <- bquote(lm(.(as.formula(mod)), dat)) lm_out5 <- eval(expr) expr <- call("lm", as.formula(mod), as.symbol("dat")) lm_out6 <- eval(expr) but bquote is usually easier and good enough. On Wed, Oct 25, 2023, 05:10 Shu Fai Cheung wrote: > Hi All, > > I have a pro

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Shu Fai Cheung
Sorry for a typo, regarding the first attempt, lm_out2, using do.call(), I meant: 'It does have the formula, "as a formula": y ~ x1 + x2. However, the name "dat" is evaluated. ...' Regards, Shu Fai On Wed, Oct 25, 2023 at 5:09 PM Shu Fai Cheung wrote: > > Hi All, > > I have a problem that may h

Re: [R] Create new data frame with conditional sums

2023-10-24 Thread peter dalgaard
This seems to work. A couple of fine points, including handling duplicated Pct values right, which is easier if you do the reversed cumsum. > dd2 <- dummydata[order(dummydata$Pct),] > dd2$Cum <- rev(cumsum(rev(dd2$Totpop))) > use <- !duplicated(dd2$Pct) > approx(dd2$Pct[use], dd2$Cum[use], ctof,

Re: [R] Create new data frame with conditional sums

2023-10-16 Thread Bert Gunter
Sorry, misstatements. It should (of course) read: If one makes the reasonable assumption that Pct is much larger than Cutoff, sorting Pct is the expensive part e.g O(nlog2(n) for Quicksort (n = length Pct). I believe looping is O(n^2). etc. On Mon, Oct 16, 2023 at 7:48 AM Bert Gunter wrote: > >

Re: [R] Create new data frame with conditional sums

2023-10-16 Thread Bert Gunter
If one makes the reasonable assumption that Pct is much larger than Cutoff, sorting Cutoff is the expensive part e.g O(nlog2(n) for Quicksort (n = length Cutoff). I believe looping is O(n^2). Jeff's approach using findInterval may be faster. Of course implementation details matter. -- Bert On Mo

Re: [R] Create new data frame with conditional sums

2023-10-16 Thread Leonard Mada via R-help
Dear Jason, The code could look something like: dummyData = data.frame(Tract=seq(1, 10, by=1),     Pct = c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03),     Totpop = c(4000,3500,4500,4100,3900,4250,5100,4700,4950,4800)) # Define the cutoffs # - allow for duplicate entries; by = 0.03; # by

Re: [R] Create new data frame with conditional sums

2023-10-15 Thread Leonard Mada via R-help
Dear Jason, I do not think that the solution based on aggregate offered by GPT was correct. That quasi-solution only aggregates for every individual level. As I understand, you want the cumulative sum. The idea was proposed by Bert; you need only to sort first based on the cutoff (e.g. usin

Re: [R] Create new data frame with conditional sums

2023-10-15 Thread Jason Stout, M.D.
After I sent this, a colleague referred me to the GPT-4 interface on Bing. I entered the exact email query below and it provided the following solution, which worked for the toy example and was successfully adapted to my application: # Define the cutoffs cutoffs <- seq(0, 0.15, by = 0.01) # Cr

Re: [R] Create new data frame with conditional sums

2023-10-14 Thread Jeff Newmiller via R-help
Pre-compute the per-interval answers and use findInterval to look up the per-row answers... dat <- read.table( text= "Tract Pct Totpop 1 0.054000 2 0.033500 3 0.014500 4 0.124100 5 0.

Re: [R] Create new data frame with conditional sums

2023-10-14 Thread Bert Gunter
Well, here's one way to do it: (dat is your example data frame) Cutoff <- seq(0, .15, .01) Pop <- with(dat, sapply(Cutoff, \(p)sum(Totpop[Pct >= p]))) I think there must be a more efficient way to do it with cumsum(), though. Cheers, Bert On Sat, Oct 14, 2023 at 12:53 AM Jason Stout, M.D. wrot

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-04 Thread avi.e.gross
lf Of Sorkin, John Sent: Tuesday, July 4, 2023 12:17 AM To: Rolf Turner ; Bert Gunter Cc: r-help@r-project.org (r-help@r-project.org) ; Achim Zeileis Subject: Re: [R] Create a variable lenght string that can be used in a dimnames statement My life is complete. I have inspired a fortune! John

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-04 Thread Ivan Krylov
(Sorry for the double post.) On Tue, 4 Jul 2023 10:14:43 +0300 Ivan Krylov wrote: > Try replacing the _second_ paste() in the example above with a c(). What I had forgotten to mention is that you also need to replace the initial assignment > string="" with the following: string = charact

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-04 Thread Ivan Krylov
On Mon, 3 Jul 2023 20:08:06 + "Sorkin, John" wrote: > # create variable names xxx1 and xxx2. > string="" > for (j in 1:2){ > name <- paste("xxx",j,sep="") > string <- paste(string,name) > print(string) > } > # Creation of xxx1 and xxx2 works > string You need to distinguish between a s

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-03 Thread Sorkin, John
My life is complete. I have inspired a fortune! John From: Rolf Turner Sent: Monday, July 3, 2023 6:34 PM To: Bert Gunter Cc: Sorkin, John; r-help@r-project.org (r-help@r-project.org); Achim Zeileis Subject: Re: [R] Create a variable lenght string that

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-03 Thread Ebert,Timothy Aaron
At least on my system string has a single value of " xxx1 xxx2" not "xxx1" and "xxx2". The variable zzz has two values: "J K xxx1" and "J K xxx2" What you want is "J", "K", "xxx1", "xxx2" If I cheat everything works. So then the goal is to rewrite the program so cheating is not needed. # cr

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-03 Thread Rolf Turner
On Mon, 3 Jul 2023 13:40:41 -0700 Bert Gunter wrote: > I am not going to try to sort out your confusion, as others have > already tried and failed. Fortune nomination!!! cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Stats. Dep't. (secreta

Re: [R] Create a variable lenght string that can be used in a dimnames statement

2023-07-03 Thread Bert Gunter
I am not going to try to sort out your confusion, as others have already tried and failed. But I will point out that "string" of variables is pretty much nonsense in R. A "character vector"/"vector of strings" is probably what you mean and want to provide column names // names for the second compon

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Rui Barradas
quot; to the string of column names zzz <- paste("j","k",string) zzz # assign column names, j, k, xxx1, xxx2 to the matrix # create column names, j, k, xxx1, xxx2. dimnames(myvalues)<-list(NULL,c(zzz)) colnames(myvalues)<-zzz ____ F

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Rui Barradas
aste("j","k",string) zzz # assign column names, j, k, xxx1, xxx2 to the matrix # create column names, j, k, xxx1, xxx2. dimnames(myvalues)<-list(NULL,c(zzz)) colnames(myvalues)<-zzz ____ From: Jeff Newmiller Sent: Monday, July 3, 2023

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Sorkin, John
umn names, j, k, xxx1, xxx2 to the matrix # create column names, j, k, xxx1, xxx2. dimnames(myvalues)<-list(NULL,c(zzz)) colnames(myvalues)<-zzz ____ From: Jeff Newmiller Sent: Monday, July 3, 2023 2:45 PM To: Sorkin, John Cc: r-help@r-project.org Subj

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Jeff Newmiller
I really think you should read that help page. colnames() accesses the second element of dimnames() directly. On July 3, 2023 11:39:37 AM PDT, "Sorkin, John" wrote: >Jeff, >Thank you for your reply. >I should have said with dim names not column names. I want the Mateix to have >dim names, no

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Sorkin, John
Jeff, Thank you for your reply. I should have said with dim names not column names. I want the Mateix to have dim names, no row names, dim names j, k, xxx1, xxx2. John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medici

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Rui Barradas
Às 19:00 de 03/07/2023, Sorkin, John escreveu: I am trying to create an array, myvalues, having 2 rows and 4 columns, where the column names are j,k,xxx1,xxx2. The code below fails, with the following error, "Error in dimnames(myvalues) <- list(NULL, zzz) : length of 'dimnames' [2] not equal

Re: [R] Create matrix with column names wiht the same prefix xxxx and that end in 1, 2

2023-07-03 Thread Jeff Newmiller
?colnames On July 3, 2023 11:00:32 AM PDT, "Sorkin, John" wrote: >I am trying to create an array, myvalues, having 2 rows and 4 columns, where >the column names are j,k,xxx1,xxx2. The code below fails, with the following >error, "Error in dimnames(myvalues) <- list(NULL, zzz) : > length of '

Re: [R] Create a categorical variable using the deciles of data

2022-06-15 Thread Richard O'Keefe
but they too take one approach to solve a problem rather > than "here is a problem" and "these are all possible solutions." I > appreciate seeing alternative solutions. > > Tim > > -Original Message- > From: R-help On Behalf Of Richard O'Kee

Re: [R] Create a categorical variable using the deciles of data

2022-06-14 Thread Ebert,Timothy Aaron
Hana, the "right" answer depends on exactly what you need. Here are three correct solutions. They use the same basic strategy to give different results. There are also other approaches in R to get the same outcome. You could use data_catigocal[i,j] and some for loops. size1 <-5 ngroup <- 1

Re: [R] create distinct variable names

2022-05-14 Thread Rui Barradas
Hello, Replace the for loop by a lapply loop and assign the names after, with sprintf("Corr%d", 1:10) Is out a data.frame? Can you post dput(head(out))? Hope this helps, Rui Barradas Às 18:33 de 14/05/2022, Sorkin, John escreveu: I am trying to create distinct variable names of the form Co

Re: [R] create mean ksvm model

2021-10-23 Thread Luigi Marongiu
Thank you for the clarification. On Sat, Oct 23, 2021 at 11:42 PM Bert Gunter wrote: > > You appear to be bombarding the list with statistics questions. Please note > per the posting guide linked below: > > "Questions about statistics: The R mailing lists are primarily intended for > questions

Re: [R] create mean ksvm model

2021-10-23 Thread Bert Gunter
You appear to be bombarding the list with statistics questions. Please note per the posting guide linked below: "*Questions about statistics:* The R mailing lists are primarily intended for questions and discussion about the R software. However, questions about statistical methodology are sometime

Re: [R] Create a function problem

2021-05-16 Thread PIKAL Petr
rner > Subject: Re: [R] Create a function problem > > Hi Rolf, > I am a beginner for R. > I have a date frame raw. it contents the fields of pedigree.name, UPN, > Test.Result.tr_Test.Result1, Result.tr_gene1, > Test.Result.tr_Variant..nucleotide.1 .. Test.Result.

Re: [R] Create a function problem

2021-05-14 Thread Mathew Guilfoyle
Have you tried putting the a,b, and c column names you are passing in quotes i.e. as strings? Currently your function is expecting separate objects with those names. The select function itself can accept unquoted column names, as can others in R, because specific processing they do in the backg

Re: [R] Create a function problem

2021-05-14 Thread Rolf Turner
On Sat, 15 May 2021 00:55:08 + (UTC) Kai Yang wrote: > Hi Rolf, > I am a beginner for R. Then I suggest that you spend some time learning basic R syntax, with the help of some of the excellent online tutorials. "An Introduction to R" from https://cran.r-project.org/manuals.html would be a g

Re: [R] Create a function problem

2021-05-14 Thread Kai Yang via R-help
Hi Rolf, I am a beginner for R.  I have a date frame raw. it contents the fields of pedigree.name, UPN, Test.Result.tr_Test.Result1, Result.tr_gene1, Test.Result.tr_Variant..nucleotide.1 .. Test.Result.tr_Test.Result20, Result.tr_gene20, Test.Result.tr_Variant..nucleotide.20 Basically, I wa

Re: [R] Create a function problem

2021-05-14 Thread Rolf Turner
On Fri, 14 May 2021 17:42:12 + (UTC) Kai Yang via R-help wrote: > Hello List, I was trying to write a function. But I got a error > message. Can someone help me how to fix it? Many thanks,Kai > > k_subset <- function(p, a, b, c){ > +   p  <- select(raw > +                ,Pedigree.name > +

Re: [R] create

2021-01-27 Thread Bert Gunter
Thanks for the reprex. I think this is one way to do what you want: dt$flag2 <- 0 + with(dt,Item == "DESK" & check %in% code2) > dt$flag2 <- 0 + with(dt,Item == "DESK" & check %in% code2) > dt name Item check flag2 1A DESK NORF 0 2B RANGE GARRA 0 3C CLOCK PALM 0 4

Re: [R] create a r list from dataframe using the first column as list names

2020-04-10 Thread Bert Gunter
"I thought: why make this overly complicated,..." Indeed, though "complicated" is in the eyes of the beholder. One wonders whether any of this is necessary, though: see ?apply , as in apply(a, 1, whatever...) to do things rowwise. Cheers, Bert Bert Gunter "The trouble with having an open mind i

Re: [R] create a r list from dataframe using the first column as list names

2020-04-10 Thread Rasmus Liland
On 2020-04-09 18:00 +, aiguo li wrote: | That is awesome! Thanks. Dear AiGuo, I thought: why make this overly complicated, when this is also possible: a <- matrix(LETTERS[1:16], nrow=4) X <- split(x=a[,-1], f=a[,1]) lapply(X=X, FUN=as.factor) Best, Rasmus _

Re: [R] create a r list from dataframe using the first column as list names

2020-04-09 Thread Rasmus Liland
On 2020-04-09 18:00 +, aiguo li wrote: | That is awesome! Thanks. I'm glad this was helpful for you! __ 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

Re: [R] create a r list from dataframe using the first column as list names

2020-04-09 Thread Rasmus Liland
On 2020-04-09 18:50 +0100, Rui Barradas wrote: | Hello, | | Your post is unreadable, please repost in | *plain text*, not HTML. Hi! It was not so bad? I was able to extract out the core parts at least to prepare an answer ... maybe a bit hard with no line breaks, but ... Best, Rasmus ___

Re: [R] create a r list from dataframe using the first column as list names

2020-04-09 Thread Rui Barradas
Hello, Your post is unreadable, please repost in *plain text*, not HTML. Rui Barradas Às 16:00 de 09/04/20, aiguo li via R-help escreveu: Hello allI need to create a r list with each row as a list object and named with the element in the first column.  Illustrated below:> a<- as.data.frame(m

Re: [R] create a r list from dataframe using the first column as list names

2020-04-09 Thread Rasmus Liland
On 2020-04-09 15:00 +, aiguo li via R-help wrote: | Hello allI need to create a r list with | each row as a list object and named with | the element in the first column.  Dear aiguo, Perhaps this fits your bill? a <- matrix(LETTERS[1:16], nrow = 4) FUN <- function(x) { as.factor(x[-1]

Re: [R] create a table for time difference (from t3 to t1, so on..)

2019-05-04 Thread Jim Lemon
Hi Marna, I was able to have another look at it. I think this is what you want except for the column names (I'm lazy): dAT<-structure(list(Id = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 5L, 4L, 1L, 6L, 6L, 3L, 4L, 1L), .Label = c("a", "b", "c", "e", "f", "m"), class = "factor"), date = structure(c(1L, 1

Re: [R] create a table for time difference (from t3 to t1, so on..)

2019-05-03 Thread Jim Lemon
Hi Marna, You can get the information you need with this: dAT$date<-as.Date(dAT$date,"%d-%b-%y") diffs<-function(x,maxn) return(diff(x)[1:maxn]) initdate<-function(x) return(min(x)) datediffs<-aggregate(dAT$date,list(dAT$Id),diffs,3) I can't do the manipulation of the resulting values at the mome

Re: [R] create

2019-04-13 Thread Bert Gunter
Just use a temporary variable! ## You should apply is.na() only to the numeric columns you need, not the whole data frame ## see ?'[' for why. vnew <- vdat[,3:5] vnew[is.na(vnew)] <- 0 vdat$xy <- as.matrix(vnew) %*% c(2, 5, 3) vdat I still question whether this is wise; but that's for you to dete

Re: [R] create

2019-04-13 Thread Val
Sorry for the confusion, my sample data does not represent the actual data set. The range of value can be from -ve to +ve values and 0 could be a true value of an observation. So, instead of replacing missing value by zero, I want exclude them from the calculation. On Sat, Apr 13, 2019 at

Re: [R] create

2019-04-13 Thread Jeff Newmiller
Looks to me like your initial request contradicts your clarification. Can you explain this discrepancy? On April 13, 2019 8:29:59 PM PDT, Val wrote: >Hi Bert and Jim, >Thank you for the suggestion. >However, those missing values should not be replaced by 0's. >I want exclude those missing values

Re: [R] create

2019-04-13 Thread Val
Hi Bert and Jim, Thank you for the suggestion. However, those missing values should not be replaced by 0's. I want exclude those missing values from the calculation and create the index using only the non-missing values. On Sat, Apr 13, 2019 at 10:14 PM Jim Lemon wrote: > > Hi Val, > For this pa

Re: [R] create

2019-04-13 Thread Bert Gunter
If the NA's are really 0's, replace them with 0 before doing the calculation. (see ?is.na). If they are not 0's, think again about doing this as the results would probably mislead. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." --

Re: [R] create

2019-04-13 Thread Jim Lemon
Hi Val, For this particular problem, you can just replace NAs with zeros. vdat[is.na(vdat)]<-0 vdat$xy <- 2*(vdat$x1) + 5*(vdat$x2) + 3*(vdat$x3) vdat obs Year x1 x2 x3 xy 1 1 2001 25 10 10 130 2 2 2001 0 15 25 150 3 3 2001 50 10 0 150 4 4 2001 20 0 60 220 Note that this is not a gen

Re: [R] Create a sequence

2019-04-09 Thread Eric Berger
2019 8:21 AM > To: bienvenidoz...@gmail.com > Cc: R-help > Subject: Re: [R] Create a sequence > > > > > On Apr 9, 2019, at 9:07 AM, bienvenidoz...@gmail.com wrote: > > > > how to create > > u = (1, −1, 2, −2, . . . , 100, −100) in r > > > > Tha

Re: [R] Create a sequence

2019-04-09 Thread David L Carlson
--Original Message- From: R-help On Behalf Of Marc Schwartz via R-help Sent: Tuesday, April 9, 2019 8:21 AM To: bienvenidoz...@gmail.com Cc: R-help Subject: Re: [R] Create a sequence > On Apr 9, 2019, at 9:07 AM, bienvenidoz...@gmail.com wrote: > > how to create > u = (1, −1, 2

Re: [R] Create a sequence

2019-04-09 Thread Marc Schwartz via R-help
> On Apr 9, 2019, at 9:07 AM, bienvenidoz...@gmail.com wrote: > > how to create > u = (1, −1, 2, −2, . . . , 100, −100) in r > > Thanks > Bienvenue Hi, See ?seq and ?rep > rep(seq(100), each = 2) * c(1, -1) [1]1 -12 -23 -34 -45 -56 -67 [14] -7

Re: [R] create a network for a small text df

2019-02-01 Thread Jeff Newmiller
I an finding your question very opaque. For one thing, why aren't you specifying any edges? Since I don't do this kind of analysis normally I don't know what your combined graph should look like. Can you provide a link you what you hope to end up with? Note that the Posting Guide emphasizes tha

Re: [R] create a network for a small text df

2019-02-01 Thread Elahe chalabi via R-help
Thanks for your reply but it does not solve the problem. Since I have 7 text rows in my df then I have to run something like net2=graph(c("account","block","block","solve","solve","problem")) for each, I'm looking for a way to bring all the relations in one single plot On Thursday, January 3

Re: [R] Create a new list from selected items in another list

2019-01-26 Thread Jeff Newmiller
BBB <- lapply( CCC, function( v ) v[ 0 wrote: >Hi All-- > >I have a list which contain variables 0s at the end of each vector on >the isit. I want to create a new list with only numbers > 0. >It seems simple, but i tried several option, none of which worked. > >CCC <- list(A=c(1,2,3,0,0,0,0), B=c(

Re: [R] create groups from data with duplicates, such that each group has a duplicate represented once

2019-01-17 Thread Kevin Wamae
Dear Petr, thank you for the guidance. A colleague managed to solve it I'll definitely use "dput" for future postings. Regards -- Kevin Wamae On 17/01/2019, 03:57, "PIKAL Petr" wrote: Hi Instead of attachment which is usually removed you should use dput

Re: [R] create groups from data with duplicates, such that each group has a duplicate represented once

2019-01-17 Thread PIKAL Petr
Hi Instead of attachment which is usually removed you should use dput Something like output from dput(head(yourdata,30)) To remove duplicate values see unique or duplicated Cheers Petr > -Original Message- > From: R-help On Behalf Of Kevin Wamae > Sent: Thursday, January 17, 2019 1:2

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-20 Thread Ding, Yuan Chun
Hi David, Thank you so much for your kind suggestion and fixing my code!! I learn a lot from you today. Ding -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Thursday, April 19, 2018 6:58 PM To: Ding, Yuan Chun Cc: r-help@r-project.org Subject: Re: [R

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread David Winsemius
> On Apr 19, 2018, at 1:22 PM, David Winsemius wrote: > > >> On Apr 19, 2018, at 11:20 AM, Ding, Yuan Chun wrote: >> >> Hi All, >> >> I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno >> (a data frame) based on log2pfoa values. I can do it using the following >>

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread David Winsemius
> On Apr 19, 2018, at 11:20 AM, Ding, Yuan Chun wrote: > > Hi All, > > I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno > (a data frame) based on log2pfoa values. I can do it using the following code. > > pfas.pheno <-within(pfas.pheno, {cat.pfoa<-NA > cat.pfoa[pf

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread Ding, Yuan Chun
Hi Rui, Thank you very much for your help!! It works very well, I got it. Ding -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Thursday, April 19, 2018 11:35 AM To: Ding, Yuan Chun ; r-help@r-project.org Subject: Re: [R] create multiple categorical

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread Rui Barradas
Hello, When programming it is better to use dat[["variable"]] than dat$variable. So your code could be pfas.pheno[[cat.var]] <- NA pfas.pheno[[cat.var]][pfas.pheno[,i] <= quantile(pfas.pheno[,i],0.25, na.rm =T)] <- 0 etc. Untested. Hope this helps, Rui Barradas On 4/19/2018 7:20 PM, Ding

Re: [R] create waveform sawtooth

2017-11-13 Thread Michael Tiemann
Here is perhaps a better sawtooth wave generator: sawtooth <- function(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), reverse = FALSE, ...){ xunit <- match.arg(xunit) durFrom <- preWaveform(freq = freq

Re: [R] create waveform sawtooth

2017-11-12 Thread Jeff Newmiller
Ccing the maintainer if the tuneR package. Looks to me like sawtooth (and square) don't behave as expected when using xunit="samples". Workaround is to use xunit="time" instead: sawtooth(110,duration=1/100,samp.rate=sample_rate,xunit="time") I looked at the code but found it to be opaque. --

Re: [R] create waveform sawtooth

2017-11-12 Thread Michael Tiemann
My tuneR sawtooth wave function generator is broken. When I use the sine function, I get exactly what I expect: a sine wave whose frequency is defined by the freq parameter. In particular, higher frequencies have shorter wavelengths (more cycles per second means shorter waves). When I create

Re: [R] create a loop

2017-10-21 Thread Ismail SEZEN
you sould look at "boot" package. also search "bootstrap R" keywords in google. 20 Eki 2017 23:12 tarihinde "Marna Wagley" yazdı: > Hi R Users, > I do have very big data sets and wanted to run some of the analyses many > times with randomization (1000 times). > I have done the analysis using an

Re: [R] create a correct list from Document Term Matrix

2017-05-06 Thread David Winsemius
> On May 6, 2017, at 8:14 AM, David Winsemius wrote: > >> >> On May 6, 2017, at 7:47 AM, Elahe chalabi via R-help >> wrote: >> >> Hi all, >> >> I have a text classification task which is classification of a Control group >> and Alzheimer group texts. I have generated DocumentTermMatrix for

Re: [R] create a correct list from Document Term Matrix

2017-05-06 Thread David Winsemius
> On May 6, 2017, at 7:47 AM, Elahe chalabi via R-help > wrote: > > Hi all, > > I have a text classification task which is classification of a Control group > and Alzheimer group texts. I have generated DocumentTermMatrix for both > groups and then created a list with one extra element showi

Re: [R] create new

2017-03-25 Thread Jim Lemon
Hi Val, How about this: cinmat<- matrix(c(mydat$x1>0,mydat$x1==0&mydat$x2==0,mydat$x1==0&mydat$x2>0), ncol=3) mydat$x4<-rowSums(mydat[,c("x1","x3","x2")]*cinmat) Jim On Sat, Mar 25, 2017 at 2:56 PM, Val wrote: > Hi all, > > > I have several variables in a group and one group contains three

Re: [R] create new

2017-03-24 Thread Bert Gunter
?ifelse Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Mar 24, 2017 at 8:56 PM, Val wrote: > Hi all, > > > I have several variables in a g

Re: [R] Create gif from series of png files

2017-02-15 Thread Shane Carey
For those interested, I figured out a way using "convert" on the linux command line. Thanks On Tue, Feb 14, 2017 at 6:02 PM, Bert Gunter wrote: > Ulrik: > > Sheepishly Nitpicking (only because you are a regular and wise R-help > contibutor): > > gganimate is not a library, it's a package. > > N

Re: [R] Create gif from series of png files

2017-02-14 Thread Bert Gunter
Ulrik: Sheepishly Nitpicking (only because you are a regular and wise R-help contibutor): gganimate is not a library, it's a package. No need to reply. Best, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Be

Re: [R] Create gif from series of png files

2017-02-14 Thread Duncan Murdoch
On 14/02/2017 5:53 AM, Shane Carey wrote: Hi, I have many png files that I would like to stitch together, in order to make a gif file. Any ideas how I would do this? ImageMagick is good for this. The magick package in R makes most (all?) of its features available. The image_animate() funct

Re: [R] Create gif from series of png files

2017-02-14 Thread Shane Carey
Hi Ulrick, I created the png's in R and was hoping there would be a way of stitching them together in R. Is there a different forum I should be posting to? Thanks On Tue, Feb 14, 2017 at 11:33 AM, Ulrik Stervbo wrote: > Hi Shane, > > Wrong forum. This might be what you are looking for > > ffm

Re: [R] Create gif from series of png files

2017-02-14 Thread Ulrik Stervbo
Hi Shane, Wrong forum. This might be what you are looking for ffmpeg -i %03d.png output.gif Or use the library gganimate. Best Ulrik Shane Carey schrieb am Di., 14. Feb. 2017, 12:08: > Hi, > > I have many png files that I would like to stitch together, in order to > make a gif file. > > Any

Re: [R] create list of vectors in for loop

2016-12-06 Thread peter dalgaard
On 06 Dec 2016, at 11:17 , Jim Lemon wrote: > Hi Paul, > The easy to understand way is: > > n <- c(1:10) > # Create empty list to store vectors > list_of_vecs <- list() > > # Create n vectors of random numbers - length 10. This works ok. > for (i in n){ > list_of_vecs[[i]]<-rnorm(10,0,1) > }

Re: [R] create list of vectors in for loop

2016-12-06 Thread Jim Lemon
Hi Paul, The easy to understand way is: n <- c(1:10) # Create empty list to store vectors list_of_vecs <- list() # Create n vectors of random numbers - length 10. This works ok. for (i in n){ list_of_vecs[[i]]<-rnorm(10,0,1) } If you really want to use "assign": for (i in n){ vecname<-paste('v

Re: [R] create list of vectors in for loop

2016-12-06 Thread Paul Sanfilippo
Thank you Jim. On 6 December 2016 at 9:17:21 pm, Jim Lemon (drjimle...@gmail.com) wrote: Hi Paul, The easy to understand way is: n <- c(1:10) # Create empty list to store vectors list_of_vecs <- list() # Create n vectors of random numbers - length 10. This works ok. for (i in n){

Re: [R] create n suffixes of length 1:n from string of length n

2016-10-19 Thread David Winsemius
> On Oct 19, 2016, at 9:41 AM, Jeff Newmiller wrote: > > When I replace length with nchar, it works fine for me without mapply. > > substr( rep( s, nchar(s) ), 1, seq.int( nchar(s) ) ) I failed to make the second `nchar` -> `length` substitution. It now works for me as well. -- David > --

Re: [R] create n suffixes of length 1:n from string of length n

2016-10-19 Thread Jeff Newmiller
When I replace length with nchar, it works fine for me without mapply. substr( rep( s, nchar(s) ), 1, seq.int( nchar(s) ) ) -- Sent from my phone. Please excuse my brevity. On October 19, 2016 9:36:25 AM PDT, David Winsemius wrote: > >> On Oct 19, 2016, at 8:44 AM, Jeff Newmiller > wrote: >>

Re: [R] create n suffixes of length 1:n from string of length n

2016-10-19 Thread David Winsemius
> On Oct 19, 2016, at 8:44 AM, Jeff Newmiller wrote: > > These don't look like "suffixes" to me, but whatever. > > s <- "abc" > substr( rep( s, length(s) ), 1, seq.int( length(s) ) ) I suspect that `nchar` was meant instead of `length` but it still failed. How about: lets <- paste0(letters,

Re: [R] create n suffixes of length 1:n from string of length n

2016-10-19 Thread Jeff Newmiller
These don't look like "suffixes" to me, but whatever. s <- "abc" substr( rep( s, length(s) ), 1, seq.int( length(s) ) ) -- Sent from my phone. Please excuse my brevity. On October 19, 2016 8:01:10 AM PDT, Witold E Wolski wrote: >Is there a build in function, which creates n suffixes of length

Re: [R] create n suffixes of length 1:n from string of length n

2016-10-19 Thread Bob Rudis
purrr::map(paste0(letters, collapse=""), ~purrr::map2_chr(., 1:nchar(.), ~substr(.x, 1, .y)))[[1]] seems to crank really fast at least on my system what did you try that was slow? On Wed, Oct 19, 2016 at 11:01 AM, Witold E Wolski wrote: > Is there a build in function, which creates n suffixes o

Re: [R] create variable

2016-10-12 Thread David Winsemius
> On Oct 12, 2016, at 11:20 AM, Ashta wrote: > > Hi David and all, > > I want run the following script in a loop but faced difficulty. > > trt=c(1,2,2,4,5,6,7,8) > for(i in 1:length (trt)) > { > try[i] <- (select trt, date1, date2, datediff(date1,date2) as > d12diff [i] from >

Re: [R] create variable

2016-10-12 Thread Ashta
Hi David and all, I want run the following script in a loop but faced difficulty. trt=c(1,2,2,4,5,6,7,8) for(i in 1:length (trt)) { try[i] <- (select trt, date1, date2, datediff(date1,date2) as d12diff [i] from dateTable where trt=[i]") } I would appreciate if you point me

  1   2   3   4   5   6   7   8   >