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
d some error checking like making sure the first parameter is a matrix and the other two parmeters are appropriate strings. If the function will only be called once or twice it might be simpler to not use a function. Tim -Original Message- From: R-help On Behalf Of Sorkin, John Sent: M

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

2024-07-01 Thread Sorkin, John
#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 name the columns of the matrix. I want the firs

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
rep_many(1:13, rep(84,13)) > > > The same ideas can be used using a data.frame or functional programming > methods but the above is simple enough to flexibly create two vectors > specifying how much of each. > > You said you found a solution, so you may want to share what you chose

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

2024-06-13 Thread avi.e.gross
o you may want to share what you chose already. -Original Message- From: R-help On Behalf Of Francesca PANCOTTO via R-help Sent: Thursday, June 13, 2024 10:42 AM To: r-help@r-project.org Subject: [R] Create a numeric series in an efficient way Dear Contributors I am trying to create a nume

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

[R] Create a numeric series in an efficient way

2024-06-13 Thread Francesca PANCOTTO via R-help
Dear Contributors I am trying to create a numeric series with repeated numbers, not difficult task, but I do not seem to find an efficient way. This is my solution blocB <- c(rep(x = 1, times = 84), rep(x = 2, times = 84), rep(x = 3, times = 84), rep(x = 4, times = 84), rep(x = 5, times = 84), re

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

[R] Create a call but evaluate only some elements

2023-10-25 Thread Shu Fai Cheung
Hi All, I have a problem that may have a simple solution, but I am not familiar with creating calls manually. This is example calling lm() ``` r set.seed(1234) n <- 10 dat <- data.frame(x1 = rnorm(n), x2 = rnorm(n), y = rnorm(n)) lm_out <- lm(y ~ x1 + x2, dat

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.
the result result So thanks to all for considering this query�we're in a brave new world of AI-generated coding. Message: 3 Date: Fri, 13 Oct 2023 20:13:56 + From: "Jason Stout, M.D." To: "r-help@r-project.org" Subject: [R] Create new data frame with conditi

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

[R] Create new data frame with conditional sums

2023-10-14 Thread Jason Stout, M.D.
This seems like it should be simple but I can't get it to work properly. I'm starting with a data frame like this: Tract Pct Totpop 1 0.054000 2 0.033500 3 0.014500 4 0.124100 5 0.21

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
c("j","k",string) # assign column names, j, k, xxx1, xxx2 to the matrix # create column names, j, k, xxx1, xxx2. dimnames(myvalues)<-list(NULL,c(zzz)) Regards, Tim -Original Message- From: R-help On Behalf Of Sorkin, John Sent: Monday, July 3, 2023 4:08 PM T

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

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

2023-07-03 Thread Sorkin, John
Colleagues, I am sending this email again with a better description of my problem and the area where I need help. I need help creating a string of variables that will be accepted by the dimnames function. The string needs to start with the dimnames j and k followed by a series of dimnames xxx1

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 '

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

2023-07-03 Thread Sorkin, John
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 to array extent" Please help me get the code t

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
categorical2 <- cbind(option2, data_catigocal) option3 <- rep(group_vector, group_size) option3a <- sample(option3, size1, replace=FALSE) data_categorical3 <- cbind(option3a, data_catigocal) Tim -Original Message- From: R-help On Behalf Of anteneh asmare Sent: Tuesday, June 14, 2022

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

[R] create mean ksvm model

2021-10-23 Thread Luigi Marongiu
Hello, I am using the ksvm function from the library kernlab to generate an SVM classification. I am running the model with k-mean cross-validation, thus obtaining different accuracy. Is it possible to merge the different models obtained with the separate data set to generate a kind of median model

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 > +

[R] Create a function problem

2021-05-14 Thread Kai Yang via R-help
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 +                ,UPN +                ,a +                ,b +                ,c +  

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

[R] create

2021-01-27 Thread Val
Hi all, I have a sample of data as shown below, dt <-read.table(text="name Item check A DESK NORF B RANGE GARRA C CLOCKPALM D DESK RR E ALARMDESPRF H DESK RF K DESK CORR K WARF CORR G NONE RF ",header=TRUE, fill=T) I want create another

Re: [R] R create .docx file ?

2020-04-15 Thread Jeff Newmiller
Indeed, replacing ReporteRs functionality was the topic of this thread. I know... it can be a bit much to read an entire thread, but reading is needed if you want to avoid non-sequitur, especially when the thread was not on topic for this mailing list to begin with. On April 15, 2020 10:33:05 A

Re: [R] R create .docx file ?

2020-04-15 Thread Paul Bivand
However, the Reporters github page clearly says that the package has been removed from CRAN and it has been replaced by the officer package. Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer. https://cran.r-project.org/we

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] R create .docx file ?

2020-04-09 Thread A Biologist
Many thanks ! Bert Gunter's answer is of course correct. The maintainer suggests Stackoverflow or commercial advice - which is worrying as I have some further questions concerning lists in [officer} - but first I'll do some more research ! On Thu, Apr 9, 2020 at 5:12 PM Jeff Newmiller wrote: >

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

2020-04-09 Thread aiguo li via R-help
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(matrix(LETTERS[1:16],nrow = 4))> a  V1 V2 V3 V41  A  E  I  M2  B   F  J  N3  C  G  K  O4  D  H  L  P I want the list looks like$A[1] E I MLevels

Re: [R] R create .docx file ?

2020-04-09 Thread Jeff Newmiller
Rmarkdown is my first choice as well... but the options available there for controlling PDF output via LaTeX macros are incredibly powerful, while the options available for controlling Word output from Rmarkdown are extremely limited by comparison. ReporteRs and officeR provide considerably more

Re: [R] R create .docx file ?

2020-04-08 Thread Jeff Newmiller
The OP clearly hasn't followed the excellent documentation... this is not a maintainer problem. It is the act of printing the completed object that puts a file on disk. However, the package author recommends in the README that help be requested from stackoverflow, as the mailing list Posting Gu

Re: [R] R create .docx file ?

2020-04-08 Thread Bert Gunter
But the OP explicitly notes that the read_docx package does *not* write files and asks whether there are *other* packages or functions that provide that functionality. It still seems to me that the ReporteR maintainer might be the best place to go for that info, although there is certainly no assur

Re: [R] R create .docx file ?

2020-04-08 Thread Jeff Newmiller
But before hassling the maintainer the OP should read the package vignettes and run some examples... read_docx does not write to any files, so complaining that it doesn't will be fruitless. On April 8, 2020 9:31:41 AM PDT, Bert Gunter wrote: >This sounds like the sort of specialized question t

Re: [R] R create .docx file ?

2020-04-08 Thread Bert Gunter
This sounds like the sort of specialized question that should be directed to the maintainer (?maintainer) rather than to a general Help list such as this. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathe

[R] R create .docx file ?

2020-04-08 Thread A Biologist
Dear All, Mac Catalina - R 3.6.3 - all up-to-date packages. I would like to re-create the functionality which was found in the package {ReporteRs} by creating a .docx file in a folder on my computer from within R - which can subsequently be used by the {officer} function read_docx. The function re

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

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

2019-05-03 Thread Marna Wagley
Hi R User. I have a date set in which I wanted to find the duration (period) between released time and detection time for each individual. Is there any simplest way to create a matrix? I appreciate your help. Thanks, MW -- Here is the example data, dAT<-structure(list(Id = structure(

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

[R] create

2019-04-13 Thread Val
Hi All, I have a data frame with several columns and I want to create another column by using the values of the other columns. My problem is that some the row values for some columns have missing values and I could not get the result I waned . Here is the sample of my data and my attem

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

[R] Create a sequence

2019-04-09 Thread bienvenidoz...@gmail.com
how to create u = (1, −1, 2, −2, . . . , 100, −100)  in r Thanks Bienvenue [[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

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

2019-02-01 Thread Jeff Newmiller
;data.frame", row.names = c(NA, >-7L)) > >#And I ran this > >library(igraph) >net2=graph(c("account","block","block","solve","solve","problem")) >plot(net2) > ># I do not get 7 plots, only one? See attached

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

2019-02-01 Thread Elahe chalabi via R-help
his library(igraph) net2=graph(c("account","block","block","solve","solve","problem")) plot(net2) # I do not get 7 plots, only one? See attached. WHP From: R-help On Behalf Of Elahe chalabi via R-help Sent: Wednesday, January 30, 2019

[R] create a network for a small text df

2019-01-30 Thread Elahe chalabi via R-help
Hi all, I have a small dataframe and I would like to show in a network plot how words are related to the word "problem" with arrows (keeping the order of the words in sentences). Here's the df: dput(df) structure(list(text = structure(c(1L, 7L, 3L, 4L, 5L, 6L, 2L), .Label = c(

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(

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

2019-01-26 Thread Ek Esawi
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(2,3,4,5,0,0,0,0,0,0)) for (i in 1:length(CCC)) { f

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

2019-01-17 Thread Kevin Wamae
nuary 17, 2019 1:29 AM > To: r-help@r-project.org > Subject: [R] create groups from data with duplicates, such that each group has > a duplicate represented once > > Hi, I have a sequencing run with ~3000 samples (attached dataset). The > samples were initiall

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

2019-01-17 Thread PIKAL Petr
7, 2019 1:29 AM > To: r-help@r-project.org > Subject: [R] create groups from data with duplicates, such that each group has > a duplicate represented once > > Hi, I have a sequencing run with ~3000 samples (attached dataset). The > samples were initially tagged and amplified by PCR

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

2019-01-16 Thread Kevin Wamae
Hi, I have a sequencing run with ~3000 samples (attached dataset). The samples were initially tagged and amplified by PCR in duplicate. The tags used range from MID01 to MID26. MID01-MID13 were used for pair 1 while MID14-MID26 were used for pair 2. The tags are re-used to allow samples to be p

[R] create a heatmap for findAssocs results based on time

2018-11-15 Thread Elahe chalabi via R-help
Hi all, I have the following data for which I create a document term matrix first and then I add the time available to the dtm. In order to see the correlations to the term "updat" in the different years, I would like to have a heat-map for findassoc in a way that x-axis shows the time.

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 >>

  1   2   3   4   5   6   7   8   9   10   >