How to retain only one space between columns in dataframe

I want to output the dataframe as a table with no extension name, but I have problems with it. I found that after removing scientific notation, there are fixed spaces between each column. For example, there may be more than one space for some rows between 4th and 5th columns. However, I want to keep only one space between the columns, rather than fixed locations. Could anyone help me with this problem?
The data and the code are shown below. Thanks.

create a small sample

df= data.frame(V1=10:25,

keep four decimal places in columns V2 and V3

df[,2:3] = format(df[,2:3],nsmall=4)

remove scientific notation

df = format(df, scientific=F)

write the output


What you are seeing is a result of your last format() command. Try this line instead.

df = format(df, scientific=F, trim = TRUE)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.