Hi all, I have the following x1<-paste("A", 1:6, sep = "") x2<- round(rgamma(6,2,1)) x3<-paste("B", 1:6, sep = "") x4<- round(rgamma(6,2,1)) data1 <- data.frame(x1,x2,x3,x4) I would like to get data2 <- c(A1=4, A2=1, A3=0,...) Is there any standard for such a case? Thank you very much in advance, Diego ____________________________________________________________________________________ [[elided Yahoo spam]] [[alternative HTML version deleted]]
Richard.Cotton at hsl.gov.uk
2008-Apr-28 09:24 UTC
[R] Combine Values into a Vector or List
> x1<-paste("A", 1:6, sep = "") > x2<- round(rgamma(6,2,1)) > x3<-paste("B", 1:6, sep = "") > x4<- round(rgamma(6,2,1)) > data1 <- data.frame(x1,x2,x3,x4) > I would like to get > data2 <- c(A1=4, A2=1, A3=0,...) > Is there any standard for such a case?I presume that 4, 2, 0 are the first few values of x2. In which case, I think that what you want is simply this: names(x2) <- x1 Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
Hi Richard, Thanks a lot! What I actually want to have>A14>A22 ..... and so on! Is this possible? Thank you again :)! ----- Original Message ---- From: "Richard.Cotton@hsl.gov.uk" <Richard.Cotton@hsl.gov.uk> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: r-help@stat.math.ethz.ch; r-help-bounces@r-project.org Sent: Monday, April 28, 2008 11:24:12 AM Subject: Re: [R] Combine Values into a Vector or List> x1<-paste("A", 1:6, sep = "") > x2<- round(rgamma(6,2,1)) > x3<-paste("B", 1:6, sep = "") > x4<- round(rgamma(6,2,1)) > data1 <- data.frame(x1,x2,x3,x4) > I would like to get > data2 <- c(A1=4, A2=1, A3=0,...) > Is there any standard for such a case?I presume that 4, 2, 0 are the first few values of x2. In which case, I think that what you want is simply this: names(x2) <- x1 Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:28}}
Thank you Jorge, what I want to have is> z <- A1+A2 >z4 The problem is that A1, A2,... still unknown, so that I have the following error> A1object "A1" not found Thank you in advance! ----- Original Message ---- From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: R mailing list <r-help@r-project.org> Sent: Tuesday, April 29, 2008 7:38:41 PM Subject: Re: [R] Combine Values into a Vector or List Hi Diego, Is this what you want? # Data set set.seed(123) x1<-paste("A", 1:6, sep = "") x2<- round(rgamma(6,2,1)) x3<-paste("B", 1:6, sep = "") x4<- round(rgamma(6,2,1)) data1 <- data.frame(x1,x2,x3,x4) data1 x1 x2 x3 x4 1 A1 1 B1 0 2 A2 3 B2 0 3 A3 0 B3 3 4 A4 2 B4 2 5 A5 4 B5 2 6 A6 2 B6 2 # A's As=as.numeric(t(data1[,1:2])[-1,]) names(As)=paste('A',1:length(As),sep="") As A1 A2 A3 A4 A5 A6 1 3 0 2 4 2 # B's Bs=as.numeric(t(data1[,3:4])[-1,]) names(Bs)=paste('B',1:length(Bs),sep="") Bs B1 B2 B3 B4 B5 B6 0 0 3 2 2 2 HTH, Jorge On Tue, Apr 29, 2008 at 1:20 PM, Diego Culattoni <diegoculattoni@yahoo.com> wrote: Hi Richard, Thanks a lot! What I actually want to have>A14>A22 ...... and so on! Is this possible? Thank you again :)! ----- Original Message ---- From: "Richard.Cotton@hsl.gov.uk" <Richard.Cotton@hsl.gov.uk> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: r-help@stat.math.ethz.ch; r-help-bounces@r-project.org Sent: Monday, April 28, 2008 11:24:12 AM Subject: Re: [R] Combine Values into a Vector or List> x1<-paste("A", 1:6, sep = "") > x2<- round(rgamma(6,2,1)) > x3<-paste("B", 1:6, sep = "") > x4<- round(rgamma(6,2,1)) > data1 <- data.frame(x1,x2,x3,x4) > I would like to get > data2 <- c(A1=4, A2=1, A3=0,...) > Is there any standard for such a case?I presume that 4, 2, 0 are the first few values of x2. In which case, I think that what you want is simply this: names(x2) <- x1 Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:16}}
Hi Diego, Try this: z<-As["A1"]+As["A2"]; names(z)<-"z" z 4 HTH, Jorge On Tue, Apr 29, 2008 at 2:57 PM, Diego Culattoni <diegoculattoni@yahoo.com> wrote:> Thank you Jorge, what I want to have is > > z <- A1+A2 > >z > 4 > The problem is that A1, A2,... still unknown, so that I have the following > error > > A1 > object "A1" not found > > Thank you in advance! > > ----- Original Message ---- > From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> > To: Diego Culattoni <diegoculattoni@yahoo.com> > Cc: R mailing list <r-help@r-project.org> > Sent: Tuesday, April 29, 2008 7:38:41 PM > Subject: Re: [R] Combine Values into a Vector or List > > > Hi Diego, > > Is this what you want? > > # Data set > set.seed(123) > x1<-paste("A", 1:6, sep = "") > x2<- round(rgamma(6,2,1)) > x3<-paste("B", 1:6, sep = "") > x4<- round(rgamma(6,2,1)) > data1 <- data.frame(x1,x2,x3,x4) > data1 > x1 x2 x3 x4 > 1 A1 1 B1 0 > 2 A2 3 B2 0 > 3 A3 0 B3 3 > 4 A4 2 B4 2 > 5 A5 4 B5 2 > 6 A6 2 B6 2 > > # A's > As=as.numeric(t(data1[,1:2])[-1,]) > names(As)=paste('A',1:length(As),sep="") > As > A1 A2 A3 A4 A5 A6 > 1 3 0 2 4 2 > > # B's > Bs=as.numeric(t(data1[,3:4])[-1,]) > names(Bs)=paste('B',1:length(Bs),sep="") > Bs > B1 B2 B3 B4 B5 B6 > 0 0 3 2 2 2 > > HTH, > > Jorge > > > On Tue, Apr 29, 2008 at 1:20 PM, Diego Culattoni <diegoculattoni@yahoo.com> > wrote: > > > Hi Richard, > > > > Thanks a lot! What I actually want to have > > >A1 > > 4 > > >A2 > > 2 > > ...... and so on! Is this possible? > > > > Thank you again :)! > > > > > > ----- Original Message ---- > > From: "Richard.Cotton@hsl.gov.uk" <Richard.Cotton@hsl.gov.uk> > > To: Diego Culattoni <diegoculattoni@yahoo.com> > > Cc: r-help@stat.math.ethz.ch; r-help-bounces@r-project.org > > Sent: Monday, April 28, 2008 11:24:12 AM > > Subject: Re: [R] Combine Values into a Vector or List > > > > > x1<-paste("A", 1:6, sep = "") > > > x2<- round(rgamma(6,2,1)) > > > x3<-paste("B", 1:6, sep = "") > > > x4<- round(rgamma(6,2,1)) > > > data1 <- data.frame(x1,x2,x3,x4) > > > I would like to get > > > data2 <- c(A1=4, A2=1, A3=0,...) > > > Is there any standard for such a case? > > > > I presume that 4, 2, 0 are the first few values of x2. In which case, I > > think that what you want is simply this: > > > > names(x2) <- x1 > > > > Regards, > > Richie. > > > > Mathematical Sciences Unit > > HSL > > > > > > ------------------------------------------------------------------------ > > ATTENTION: > > > > This message contains privileged and confidential > > inform...{{dropped:28}} > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > ------------------------------ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now.<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ> >[[alternative HTML version deleted]]
Hello Jorge, Sorry, my aim is to get each individual separately, so that if I input> A1 # the the result would be1 This because I would like to use lm.D <- lm(y~A1+A1+A3...) Thanks, Diego ----- Original Message ---- From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: R mailing list <r-help@r-project.org> Sent: Tuesday, April 29, 2008 9:03:20 PM Subject: Re: [R] Combine Values into a Vector or List Hi Diego, Try this: z<-As["A1"]+As["A2"]; names(z)<-"z" z 4 HTH, Jorge On Tue, Apr 29, 2008 at 2:57 PM, Diego Culattoni <diegoculattoni@yahoo.com> wrote: Thank you Jorge, what I want to have is> z <- A1+A2 >z4 The problem is that A1, A2,... still unknown, so that I have the following error> A1object "A1" not found Thank you in advance! ----- Original Message ---- From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: R mailing list <r-help@r-project.org> Sent: Tuesday, April 29, 2008 7:38:41 PM Subject: Re: [R] Combine Values into a Vector or List Hi Diego, Is this what you want? # Data set set.seed(123) x1<-paste("A", 1:6, sep = "") x2<- round(rgamma(6,2,1)) x3<-paste("B", 1:6, sep = "") x4<- round(rgamma(6,2,1)) data1 <- data.frame(x1,x2,x3,x4) data1 x1 x2 x3 x4 1 A1 1 B1 0 2 A2 3 B2 0 3 A3 0 B3 3 4 A4 2 B4 2 5 A5 4 B5 2 6 A6 2 B6 2 # A's As=as.numeric(t(data1[,1:2])[-1,]) names(As)=paste('A',1:length(As),sep="") As A1 A2 A3 A4 A5 A6 1 3 0 2 4 2 # B's Bs=as.numeric(t(data1[,3:4])[-1,]) names(Bs)=paste('B',1:length(Bs),sep="") Bs B1 B2 B3 B4 B5 B6 0 0 3 2 2 2 HTH, Jorge On Tue, Apr 29, 2008 at 1:20 PM, Diego Culattoni <diegoculattoni@yahoo.com> wrote: Hi Richard, Thanks a lot! What I actually want to have>A14>A22 ....... and so on! Is this possible? Thank you again :)! ----- Original Message ---- From: "Richard.Cotton@hsl.gov.uk" <Richard.Cotton@hsl.gov.uk> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: r-help@stat.math.ethz.ch; r-help-bounces@r-project.org Sent: Monday, April 28, 2008 11:24:12 AM Subject: Re: [R] Combine Values into a Vector or List> x1<-paste("A", 1:6, sep = "") > x2<- round(rgamma(6,2,1)) > x3<-paste("B", 1:6, sep = "") > x4<- round(rgamma(6,2,1)) > data1 <- data.frame(x1,x2,x3,x4) > I would like to get > data2 <- c(A1=4, A2=1, A3=0,...) > Is there any standard for such a case?I presume that 4, 2, 0 are the first few values of x2. In which case, I think that what you want is simply this: names(x2) <- x1 Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:24}}
Maybe Matching Threads
- plot with diffrent colour and plotting symbols
- bootstrap
- [Aarch64 v2 00/18] Patches to enable Aarch64 (version 2)
- [Aarch64 00/11] Patches to enable Aarch64 (arm64) optimizations, rebased to current master.
- [AArch64 neon intrinsics v4 0/5] Rework Neon intrinsic code for Aarch64 patchset