简体   繁体   中英

One dataframe column not respecting decimal-delimiter character in write.table

I'm trying to output data in R using the following command:

write.table(df,file=OutputFile,append=FALSE,row.names=FALSE,col.names=FALSE,sep="\t",dec=",") 

df looks like: 

   col1 col2 col3 
1 89.6    89.3  89.8
2 89.7  88.9    90.5 
3 89.8  88.5    91.1 

OutputFile contains the path to where I want to write df. My problem is that the output looks like this:

89.6    89,3    89,8
89.7    88,9    90,5 
89.8    88,5    91,1 

The first column still has a dot as decimal delimiter, instead of a comma. Does anyone know what could cause this? I am using version 3.2.1.

Thank you very much, lukeA! You are right, the first column contains an Arima-forecast. str(df) showed

'data.frame': 3 obs. of 3 variables:

$ col1 : Time-Series from 2015 to 2016: 89.6 89.7 89.8

$ col2 : num 89.3 88.9 88.5

$ col3: num 89.9 90.5 91.1

Wrapping as.numeric() around the forecast when filling df did the trick. Thanks again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM