In the document "R Data Import/Export", section "Output to
connections",
there is the following portion of code:
## convert decimal point to comma in output, using a pipe (Unix)
zz <- pipe(paste("sed s/\\./,/ >", "outfile"),
"w")
cat(format(round(rnorm(100), 4)), sep = "\n", file = zz)
close(zz)
## now look at the output file:
file.show(outfile, delete.file = TRUE)
Surely the last fine must be
file.show("outfile", delete.file = TRUE)
However this is not the problem, but the fact that I get something like
,1.6861
,0.1934
,0.5640
,0.5741
,0.1920
,0.1898
,1.4788
,0.1706
,0.9953
<..snipped..>
If I run from R:
zz <- file("outfile", "w")
cat(format(round(rnorm(10), 4)), sep = "\n", file = zz)
close(zz)
and then from outside R:
sed s/\\./,/ outfile
then I get it right (of course), something like
-1,3612
-0,9772
0,1524
2,4046
0,4741
0,6659
-0,8277
0,5071
0,7190
0,4088
This is fine, but it would be good to have it working in first form.
environment: R 1.7.0 on Debian linux.
regards,
Adelchi Azzalini
--
Adelchi Azzalini <azzalini at stat.unipd.it>
Dipart.Scienze Statistiche, Universit? di Padova, Italia
http://azzalini.stat.unipd.it/
In R '\' has to be escaped, i.e. '\\' which means '\\'
has to be '\\\\'
(this was probably there before the help page was generated!?)
The following works
## convert decimal point to comma in output, using a pipe (Unix)
zz <- pipe(paste("sed s/\\\\./,/ >", "outfile"),
"w")
cat(format(round(rnorm(100), 4)), sep = "\n", file = zz)
close(zz)
## now look at the output file:
file.show("outfile", delete.file = TRUE)
Henrik Bengtsson
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
> Adelchi Azzalini
> Sent: den 20 maj 2003 12:44
> To: r-help at stat.math.ethz.ch
> Subject: [R] Output to connections
>
>
>
> In the document "R Data Import/Export", section "Output to
> connections", there is the following portion of code:
>
> ## convert decimal point to comma in output, using a pipe (Unix)
> zz <- pipe(paste("sed s/\\./,/ >", "outfile"),
"w")
> cat(format(round(rnorm(100), 4)), sep = "\n", file = zz)
> close(zz)
> ## now look at the output file:
> file.show(outfile, delete.file = TRUE)
>
> Surely the last fine must be
> file.show("outfile", delete.file = TRUE)
> However this is not the problem, but the fact that I get
> something like ,1.6861 ,0.1934 ,0.5640 ,0.5741 ,0.1920
> ,0.1898 ,1.4788 ,0.1706 ,0.9953 <..snipped..>
>
> If I run from R:
> zz <- file("outfile", "w")
> cat(format(round(rnorm(10), 4)), sep = "\n", file = zz)
> close(zz)
> and then from outside R:
> sed s/\\./,/ outfile
> then I get it right (of course), something like
> -1,3612
> -0,9772
> 0,1524
> 2,4046
> 0,4741
> 0,6659
> -0,8277
> 0,5071
> 0,7190
> 0,4088
>
> This is fine, but it would be good to have it working in first form.
>
> environment: R 1.7.0 on Debian linux.
>
> regards,
>
> Adelchi Azzalini
>
> --
> Adelchi Azzalini <azzalini at stat.unipd.it>
> Dipart.Scienze Statistiche, Universit? di Padova, Italia
http://azzalini.stat.unipd.it/
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Hello, I would like to extract unique elements of a variable which belongs to a list liste <- list(V1=c(1,2,3,5,2), V2=c(1,2,3,4,5)) var <- "V1" uni <- unique(liste[var]) #does not work I know that liste[var]$V1 works but for my problem, the label variable "V1" is only know through the var variable. I can I do Thanks in advance.
Philippe Hup? wrote:> Hello, > > I would like to extract unique elements of a variable which belongs to a > list > > liste <- list(V1=c(1,2,3,5,2), V2=c(1,2,3,4,5)) > var <- "V1" > uni <- unique(liste[var]) #does not work >Need to use "[[" here. liste[var] is still a list. liste[[var]] is a vector. I would avoid using "var" as a variable name since it is also the function for computing the variance.> I know that liste[var]$V1 works but for my problem, the label variable > "V1" is only know through the var variable. > > I can I do > > Thanks in advance. >lapply(liste, unique) returns a list of length(liste) containing the unique values of each element in the list. Regards, Sundar
You meant [[var]] not [var]. liste[var] is a one-element list. On Tue, 20 May 2003, Philippe Hup? wrote:> Hello, > > I would like to extract unique elements of a variable which belongs to a > list > > liste <- list(V1=c(1,2,3,5,2), V2=c(1,2,3,4,5)) > var <- "V1" > uni <- unique(liste[var]) #does not work > > I know that liste[var]$V1 works but for my problem, the label variable > "V1" is only know through the var variable. > > I can I do > > Thanks in advance. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595