How to control number of decimal digits in write.table() output?

前端 未结 2 2175
深忆病人
深忆病人 2020-12-24 11:01

When working with data (e.g., in data.frame) the user can control displaying digits by using

options(digits=3) 

and listing the data.frame

2条回答
  •  难免孤独
    2020-12-24 11:16

    You can use the function format() as in:

    write.table(format(ttf.all, digits=2), 'clipboard', sep='\t',row.names=F)
    

    format() is a generic function that has methods for many classes, including data.frames. Unlike round(), it won't throw an error if your dataframe is not all numeric. For more details on the formatting options, see the help file via ?format

提交回复
热议问题