Hi! I'm an R newbie and this should be a trivial problem, but I can't make it work and cannot find what I'm doing wrong in the literature. I entered the the command: table<-data.frame(x, scientific=F, digits=4) table This prints a column of x with 16 useless decimal places after the decimal point. Also, it prints an unwanted index number (1-20) in the left column. How do I get rid of the index column and how do I control the number of decimal places? Thanks in advance. CHV -- View this message in context: http://www.nabble.com/numeric-format-tp15700452p15700452.html Sent from the R help mailing list archive at Nabble.com.
Those are parameter to 'print'; what you want is something like:> x <- data.frame(a=runif(10)) > print(x)a 1 0.713705394 2 0.715496609 3 0.629578524 4 0.184360667 5 0.456639418 6 0.008667156 7 0.260985437 8 0.270915631 9 0.689128652 10 0.302484280> print(x,scientific=F, digits=4)a 1 0.713705 2 0.715497 3 0.629579 4 0.184361 5 0.456639 6 0.008667 7 0.260985 8 0.270916 9 0.689129 10 0.302484>On 2/26/08, cvandy <cvandy26 at gmail.com> wrote:> > Hi! > I'm an R newbie and this should be a trivial problem, but I can't make it > work and cannot find what I'm doing wrong in the literature. > I entered the the command: > table<-data.frame(x, scientific=F, digits=4) > table > This prints a column of x with 16 useless decimal places after the decimal > point. Also, it prints an unwanted index number (1-20) in the left column. > How do I get rid of the index column and how do I control the number of > decimal places? > Thanks in advance. > CHV > -- > View this message in context: http://www.nabble.com/numeric-format-tp15700452p15700452.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? Tell me what you want to do, not how you want to do it.
Without knowing what your 'x' is, it's hard to see what is happening that you don't like. Your data.frame function creates a data.frame containing columns scientific and digits, equal to FALSE and 4 for all rows, respectively. Is that what you want? cvandy wrote:> Hi! > I'm an R newbie and this should be a trivial problem, but I can't make it > work and cannot find what I'm doing wrong in the literature. > I entered the the command: > table<-data.frame(x, scientific=F, digits=4) > table > This prints a column of x with 16 useless decimal places after the decimal > point. Also, it prints an unwanted index number (1-20) in the left column. > How do I get rid of the index column and how do I control the number of > decimal places? > Thanks in advance. > CHV
Can you give a working example of what is happening and explain what is x? With a simple x vector of x <- rnorm(20, 5, 2) I don't get anything like what you seem to be getting. My code ==================================================x <- rnorm(20, 5, 2) table<-data.frame(x, scientific=F, digits=4) table ================================================== The numbers on the left are simply line numbers that are automatically printed when you are printing a dataframe to the screen. I don't see any way to supress them for a simple command such as your table You might want to have a look at print and print.default to address the digits problem By the way, table is a reserved word in R and probably should not be used as a name for a data.frame. --- cvandy <cvandy26 at gmail.com> wrote:> > Hi! > I'm an R newbie and this should be a trivial > problem, but I can't make it > work and cannot find what I'm doing wrong in the > literature. > I entered the the command: > table<-data.frame(x, scientific=F, digits=4) > table > This prints a column of x with 16 useless decimal > places after the decimal > point. Also, it prints an unwanted index number > (1-20) in the left column. > How do I get rid of the index column and how do I > control the number of > decimal places? > Thanks in advance. > CHV > -- > View this message in context: >http://www.nabble.com/numeric-format-tp15700452p15700452.html> Sent from the R help mailing list archive at > Nabble.com. > > ______________________________________________ > 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. >
Thanks, Erik, This is a partial copy of my code. I want to get rid of the left column of integers and I want to control the number of decimal places after the decimal point.> j<-0.4 > for(i in 1:20){+ j=j+0.1;cp[i]<-pnorm(-j*3)*10^6;ratio[i]<-j}> table<-data.frame(ratio,cp) > tableratio cp 1 0.5 66807.201268858 2 0.6 35930.3191129258 3 0.7 17864.4205628166 4 0.8 8197.53592459613 5 0.9 3466.97380304067 6> CHV______________________________________________ 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. -- View this message in context: http://www.nabble.com/numeric-format-tp15700452p15702792.html Sent from the R help mailing list archive at Nabble.com.