Closed dcomtois closed 8 years ago
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1] "LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1] "LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
Yes I figured so... Is there an easy way to easily clear labels from a whole dataframe, or to indicate that we don't want to import them at all with sasxport.get for instance?
Thx
2014-05-30 12:22 GMT-04:00 Frank Harrell notifications@github.com:
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1]
"LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44669995.
Something like:
for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled')
On 06/02/2014 01:12 PM, Dominic Comtois wrote:
Yes I figured so... Is there an easy way to easily clear labels from a whole dataframe, or to indicate that we don't want to import them at all with sasxport.get for instance?
Thx
2014-05-30 12:22 GMT-04:00 Frank Harrell notifications@github.com:
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1]
"LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44669995.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44871948.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
Seems we also need to clear the "label" attribute. I wrote this function that does it.
variables.
clear.labels <- function(x) { if(is.list(x)) { for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled') for(i in 1 : length(x)) attr(x[[i]],"label") <- NULL } else { class(x) <- setdiff(class(x), "labelled") attr(x, "label") <- NULL } return(x) }
Cheers, Dominic
2014-06-02 14:48 GMT-04:00 Frank Harrell notifications@github.com:
Something like:
for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled')
On 06/02/2014 01:12 PM, Dominic Comtois wrote:
Yes I figured so... Is there an easy way to easily clear labels from a whole dataframe, or to indicate that we don't want to import them at all with sasxport.get for instance?
Thx
2014-05-30 12:22 GMT-04:00 Frank Harrell notifications@github.com:
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1]
"LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44669995.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44871948.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44875863.
What happens if you leave the label attribute there and just clear the class?
On 06/02/2014 02:18 PM, Dominic Comtois wrote:
Seems we also need to clear the "label" attribute. I wrote this function that does it.
Clears class "labelled" and attribute "label" for data frames or unique
variables.
Usage: new.var <- clear.labels(labelled.var)
clear.labels <- function(x) { if(is.list(x)) { for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled') for(i in 1 : length(x)) attr(x[[i]],"label") <- NULL } else { class(x) <- setdiff(class(x), "labelled") attr(x, "label") <- NULL } return(x) }
Cheers, Dominic
2014-06-02 14:48 GMT-04:00 Frank Harrell notifications@github.com:
Something like:
for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled')
On 06/02/2014 01:12 PM, Dominic Comtois wrote:
Yes I figured so... Is there an easy way to easily clear labels from a whole dataframe, or to indicate that we don't want to import them at all with sasxport.get for instance?
Thx
2014-05-30 12:22 GMT-04:00 Frank Harrell notifications@github.com:
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1]
"LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
You're right, it works with write.table. My function is an overkill in this case, but it assures that is.vector() returns TRUE (prevents any compatibility issue with other packages/functions).
2014-06-02 16:19 GMT-04:00 Frank Harrell notifications@github.com:
What happens if you leave the label attribute there and just clear the class?
On 06/02/2014 02:18 PM, Dominic Comtois wrote:
Seems we also need to clear the "label" attribute. I wrote this function that does it.
Clears class "labelled" and attribute "label" for data frames or
unique variables.
Usage: new.var <- clear.labels(labelled.var)
clear.labels <- function(x) { if(is.list(x)) { for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled') for(i in 1 : length(x)) attr(x[[i]],"label") <- NULL } else { class(x) <- setdiff(class(x), "labelled") attr(x, "label") <- NULL } return(x) }
Cheers, Dominic
2014-06-02 14:48 GMT-04:00 Frank Harrell notifications@github.com:
Something like:
for(i in 1 : length(x)) class(x[[i]]) <- setdiff(class(x[[i]]), 'labelled')
On 06/02/2014 01:12 PM, Dominic Comtois wrote:
Yes I figured so... Is there an easy way to easily clear labels from a whole dataframe, or to indicate that we don't want to import them at all with sasxport.get for instance?
Thx
2014-05-30 12:22 GMT-04:00 Frank Harrell notifications@github.com:
No I see what you are saying - one field had , and the other one .
The presence of a label must make write.table think the variable is not numeric. So you need to remove labels before running write.table.
Frank
On 05/30/2014 09:07 AM, Dominic Comtois wrote:
It has to be related... Pls have a look
Restarting R session...
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129,8 33 2 1 532,4 63,8 3 1 730,4 95,7 4 1 1104,4 126,5 5 1 1354,1 132 6 1 1509,2 156,2> library(Hmisc)Loading required package: gridLoading required package: latticeLoading required package: survivalLoading required package: splinesLoading required package: Formula Attaching package: ‘Hmisc’ The following objects are masked from ‘package:base’:
format.pval, round.POSIXt, trunc.POSIXt, units
data(Orange)> Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals> label(Orange$age) <- "The age"> write.table(Orange,file="Orange.txt",dec=",")> head(read.table("Orange.txt")) Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Sys.getlocale()[1]
"LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C"
The dec is ignored if and only if a label is associated with the column.
Thx,
Dominic
2014-05-30 9:46 GMT-04:00 Frank Harrell notifications@github.com:
In your example I did not need to delete the label to make it work, so it seems that Hmisc was not related to your problem.
Delimited files are not the best data transfer option, but may be necessary if you do not purchase Stat/Transfer.
Frank
On 05/30/2014 08:42 AM, Dominic Comtois wrote:
So if I need to write delimited files for importation into another sofware that requires a comma as decimal, I absolutely need to clear the labels before doing so? Or is there maybe an existing function elsewhere that would comply with labeled data?
Thx,
Dominic
2014-05-30 8:55 GMT-04:00 Frank Harrell notifications@github.com:
The standard R function write.table does not support labels.
But if you add dec=',' to read.table everything works.
Frank
On 05/30/2014 01:07 AM, Dominic Comtois wrote:
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44647242.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651628.
Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44651957.
— Reply to this email directly or view it on GitHub
https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44654324.
— Reply to this email directly or view it on GitHub https://github.com/harrelfe/Hmisc/issues/11#issuecomment-44885717.
Hello. I just ran into this problem, here's a reproducible example:
library(Hmisc) data(Orange) Orange[,2:3] <- Orange[2:3] * 1.1 # introduce decimals label(Orange$age) <- "The age" write.table(Orange,file="Orange.txt",dec=",") head(read.table("Orange.txt"))
Tree age circumference 1 1 129.8 33 2 1 532.4 63,8 3 1 730.4 95,7 4 1 1104.4 126,5 5 1 1354.1 132 6 1 1509.2 156,2
Problem present both on Linux and Windows, R vers 3.1.0
Regards & thanks for this very useful package.