Hi everyone, I have got the following problem: x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4",nam2,"A.9") mydata <- data.frame(x1,x2) rownames(mydata) <- nam Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names': ‘A.4’, ‘A.9’ I am very thankful for your help! Amor [[alternative HTML version deleted]]
You are trying to create an illegal object, i.e. a data.frame with duplicate row names so its correctly signally the error. Read the definition of data.frame in ?data.frame On Tue, Apr 28, 2009 at 8:04 AM, amor Gandhi <amorigandhi at yahoo.de> wrote:> Hi everyone, > > I have got the following problem: > > x1 <- rnorm(10,5,1) > x2 <- runif(10,0,1) > nam1 <- paste("A",1:4,sep=".") > nam2 <- paste("A",6:9,sep=".") > nam <- c(nam1,"A.4",nam2,"A.9") > mydata <- data.frame(x1,x2) > rownames(mydata) <- nam > Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : > duplicate 'row.names' are not allowed > In addition: Warning message: > non-unique values when setting 'row.names': ?A.4?, ?A.9? > > I am very thankful for your help! > > Amor > > > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >
amor Gandhi wrote:> Hi everyone, > ? > I have got the following problem: > ? > x1 <- rnorm(10,5,1) > x2 <- runif(10,0,1) > nam1 <- paste("A",1:4,sep=".") > nam2 <- paste("A",6:9,sep=".") > nam <- c(nam1,"A.4",nam2,"A.9") > mydata <- data.frame(x1,x2) > rownames(mydata) <- nam > Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : > duplicate 'row.names' are not allowedThis message suggests that you have to choose unique row.names ... or assign those values as an additional column in your data.frame, if you need non unique values. Uwe Ligges> In addition: Warning message: > non-unique values when setting 'row.names': ???A.4???, ???A.9??? > ? > I am very thankful for your help! > ? > Amor > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at 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.
You have used A.4 and A.9 twice. Look at> nam# or> duplicated(nam)>>> amor Gandhi <amorigandhi at yahoo.de> 28/04/2009 13:04:03 >>>Hi everyone, *? I have got the following problem: *? x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4",nam2,"A.9") mydata <- data.frame(x1,x2) rownames(mydata) <- nam Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names': *??A.4*??, *??A.9*?? *? I am very thankful for your help! *? Amor [[alternative HTML version deleted]] ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Thank you for your reply :)! Is it possible to solve the problem by using A.4, A.4a, A.9 and A.91? How one cand do this in R? Many thanks --- S Ellison <S.Ellison@lgc.co.uk> schrieb am Di, 28.4.2009: Von: S Ellison <S.Ellison@lgc.co.uk> Betreff: Re: [R] duplicate 'row.names' are not allowed An: r-help@stat.math.ethz.ch, "amor Gandhi" <amorigandhi@yahoo.de> Datum: Dienstag, 28. April 2009, 14:17 You have used A.4 and A.9 twice. Look at> nam# or> duplicated(nam)>>> amor Gandhi <amorigandhi@yahoo.de> 28/04/2009 13:04:03 >>>Hi everyone, *á I have got the following problem: *á x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4",nam2,"A.9") mydata <- data.frame(x1,x2) rownames(mydata) <- nam Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names': *ÇÿA.4*ÇÖ, *ÇÿA.9*ÇÖ *á I am very thankful for your help! *á Amor [[alternative HTML version deleted]] ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:13}}
Yes, I would like, but what I sent you was just an example! I am reading a huge data, so I cant do it by hand, could you please tell how to do this in R, some of the names are also coming one after another. Many thanks --- Uwe Ligges <ligges@statistik.tu-dortmund.de> schrieb am Di, 28.4.2009: Von: Uwe Ligges <ligges@statistik.tu-dortmund.de> Betreff: Re: [R] duplicate 'row.names' are not allowed An: "amor Gandhi" <amorigandhi@yahoo.de> CC: r-help@stat.math.ethz.ch, "S Ellison" <S.Ellison@lgc.co.uk> Datum: Dienstag, 28. April 2009, 14:52 amor Gandhi wrote:> Thank you for your reply :)! Is it possible to solve the problem by using A.4, A.4a, A.9 and A.91? How one cand do this in R?Err, change "A.4" to "A.4a" in your code? Uwe> Many thanks > > > --- S Ellison <S.Ellison@lgc.co.uk> schrieb am Di, 28.4.2009: > > > Von: S Ellison <S.Ellison@lgc.co.uk> > Betreff: Re: [R] duplicate 'row.names' are not allowed > An: r-help@stat.math.ethz.ch, "amor Gandhi" <amorigandhi@yahoo.de> > Datum: Dienstag, 28. April 2009, 14:17 > > > You have used A.4 and A.9 twice. > > Look at >> nam > # or >> duplicated(nam) > > >>>> amor Gandhi <amorigandhi@yahoo.de> 28/04/2009 13:04:03 >>> > Hi everyone, > *á > I have got the following problem: > *á > x1 <- rnorm(10,5,1) > x2 <- runif(10,0,1) > nam1 <- paste("A",1:4,sep=".") > nam2 <- paste("A",6:9,sep=".") > nam <- c(nam1,"A.4",nam2,"A.9") > mydata <- data.frame(x1,x2) > rownames(mydata) <- nam > Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed > In addition: Warning message: > non-unique values when setting 'row.names': *ÇÿA.4*ÇÖ, *ÇÿA.9*ÇÖ > *á > I am very thankful for your help! > *á > Amor > > > [[alternative HTML version deleted]] > > > ******************************************************************* > This email and any attachments are confidential. Any u...{{dropped:19}}
Thanks, I can't use the name as a variable because I need to create a matrix which does include only numerical values! --- Uwe Ligges <ligges@statistik.tu-dortmund.de> schrieb am Di, 28.4.2009: Von: Uwe Ligges <ligges@statistik.tu-dortmund.de> Betreff: Re: [R] duplicate 'row.names' are not allowed An: "amor Gandhi" <amorigandhi@yahoo.de> CC: r-help@stat.math.ethz.ch, "S Ellison" <S.Ellison@lgc.co.uk> Datum: Dienstag, 28. April 2009, 15:04 amor Gandhi wrote:> Yes, I would like, but what I sent you was just an example! I am reading a huge data, so I cant do it by hand, could you please tell how to do this in R, some of the names are also coming one after another.But I do not understand why you would habe it as row.names and not as a separate variavle. And I do not undertsand which principle is behind your renaming. You need to give a real example. Uwe Ligges> Many thanks > > --- Uwe Ligges <ligges@statistik.tu-dortmund.de> schrieb am Di, 28.4.2009: > > > Von: Uwe Ligges <ligges@statistik.tu-dortmund.de> > Betreff: Re: [R] duplicate 'row.names' are not allowed > An: "amor Gandhi" <amorigandhi@yahoo.de> > CC: r-help@stat.math.ethz.ch, "S Ellison" <S.Ellison@lgc.co.uk> > Datum: Dienstag, 28. April 2009, 14:52 > > > > > amor Gandhi wrote: >> Thank you for your reply :)! Is it possible to solve the problem by using A.4, A.4a, A.9 and A.91? How one cand do this in R? > > > Err, change "A.4" to "A.4a" in your code? > > Uwe > > >> Many thanks >> >> >> --- S Ellison <S.Ellison@lgc.co.uk> schrieb am Di, 28.4.2009: >> >> >> Von: S Ellison <S.Ellison@lgc.co.uk> >> Betreff: Re: [R] duplicate 'row.names' are not allowed >> An: r-help@stat.math.ethz.ch, "amor Gandhi" <amorigandhi@yahoo.de> >> Datum: Dienstag, 28. April 2009, 14:17 >> >> >> You have used A.4 and A.9 twice. >> >> Look at >>> nam >> # or >>> duplicated(nam) >> >>>>> amor Gandhi <amorigandhi@yahoo.de> 28/04/2009 13:04:03 >>> >> Hi everyone, >> *á >> I have got the following problem: >> *á >> x1 <- rnorm(10,5,1) >> x2 <- runif(10,0,1) >> nam1 <- paste("A",1:4,sep=".") >> nam2 <- paste("A",6:9,sep=".") >> nam <- c(nam1,"A.4",nam2,"A.9") >> mydata <- data.frame(x1,x2) >> rownames(mydata) <- nam >> Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed >> In addition: Warning message: >> non-unique values when setting 'row.names': *ÇÿA.4*ÇÖ, *ÇÿA.9*ÇÖ >> *á >> I am very thankful for your help! >> *á >> Amor >> >> >> [[alternative HTML version deleted]] >> >> >> ******************************************************************* >> This email and any attachments are confidential. Any use...{{dropped:13}} >> >> >> >> ------------------------------------------------------------------------ >> >> ______________________________________________ >> 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. > > > >[[alternative HTML version deleted]]
Clearly, you can specify the 'extra' row names as you had already specified the duplicate names: x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4a",nam2,"A.9a") mydata <- data.frame(x1,x2) rownames(mydata) <- nam But you should obviously pay some attention to why you have duplicate names. If A.4 and A.9 are genuine duplicate observations, and if you want to do something useful with that, you would be better with a data frame like nam <- c(nam1,"A.4",nam2,"A.9") #or perhaps nam<-paste("A", c(1:4,4,5:9,9), sep=".") md2<-data.frame(x1=x1, x2=x2, groups=factor(nam) ) The row names are not usually terribly important, but the grouping might be, depending on the application. Steve E>>> amor Gandhi <amorigandhi at yahoo.de> 28/04/2009 13:33 >>>Thank you for your reply :)! Is it possible to solve the problem by using A.4, A.4a, A.9 and A.91? How one cand do this in R? Many thanks --- S Ellison <S.Ellison at lgc.co.uk> schrieb am Di, 28.4.2009: Von: S Ellison <S.Ellison at lgc.co.uk> Betreff: Re: [R] duplicate 'row.names' are not allowed An: r-help at stat.math.ethz.ch, "amor Gandhi" <amorigandhi at yahoo.de> Datum: Dienstag, 28. April 2009, 14:17 You have used A.4 and A.9 twice. Look at> nam# or> duplicated(nam)>>> amor Gandhi <amorigandhi at yahoo.de> 28/04/2009 13:04:03 >>>Hi everyone, *? I have got the following problem: *? x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4",nam2,"A.9") mydata <- data.frame(x1,x2) rownames(mydata) <- nam Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2", "A.3", : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names': *??A.4*??, *??A.9*?? *? I am very thankful for your help! *? Amor [[alternative HTML version deleted]] ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:21}}
Apologies; my earlier reply preceded this extra info. If you are reading a large file with duplicate "row names", try reading it in as is, then simply converting the numeric parts to a matrix. For example, if you had the same kind of data frame as before x1 <- rnorm(11,5,1) x2 <- runif(11,0,1) nam <- nam<-paste("A", c(1:4,4,5:9,9), sep=".") mydata <- data.frame(nam=nam, x1=x1,x2=x2) as.matrix(mydata[,2:3]) works. You can also do this on the fly, as in biplot(prcomp(as.matrix(mydata[,2:3]))) to take a very silly example.>>> amor Gandhi <amorigandhi at yahoo.de> 28/04/2009 14:03 >>>Yes, I would like, but what I sent you was just an example! I am reading a huge data, so I cant do it by hand, could you please tell how to do this in R, some of the names are also coming one after another. Many thanks ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}