Re: [R] Concatenate a Variable

2008-02-01 Thread Jorge Iván Vélez
Hi Carla,

Try paste(VAR: ,a,sep=)


Jorge


On 2/1/08, Carla Rebelo [EMAIL PROTECTED] wrote:

 Good morning!

 I do not speak English very well and so I will try to explain the best I
 can. I have this:

  tabela[,1]
 [1] a a b b a c b a c c c c c
 Levels: a b c

 unique(tabela[,1])
 [1] a b c
 Levels: a b c

 var-unique(tabela[,1])[1]

  var
 [1] a
 Levels: a b c

 But if I concatenate like this
  cat(VAR: , var, \n)

 I obtain
 VAR:  1

 and I want to obtain
 VAR: a

 How can I do this? Thanks!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Concatenate a Variable

2008-02-01 Thread Carla Rebelo
Good morning!

I do not speak English very well and so I will try to explain the best I 
can. I have this:

  tabela[,1]
[1] a a b b a c b a c c c c c
Levels: a b c

 unique(tabela[,1])
[1] a b c
Levels: a b c

 var-unique(tabela[,1])[1]

  var
[1] a
Levels: a b c

But if I concatenate like this
  cat(VAR: , var, \n)

I obtain
 VAR:  1

and I want to obtain
 VAR: a

How can I do this? Thanks!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Concatenate a Variable

2008-02-01 Thread Peter Dalgaard
Carla Rebelo wrote:
 Good morning!

 I do not speak English very well and so I will try to explain the best I 
 can. I have this:

   tabela[,1]
 [1] a a b b a c b a c c c c c
 Levels: a b c

  unique(tabela[,1])
 [1] a b c
 Levels: a b c

  var-unique(tabela[,1])[1]

   var
 [1] a
 Levels: a b c

 But if I concatenate like this
   cat(VAR: , var, \n)

 I obtain
  VAR:  1

 and I want to obtain
  VAR: a

 How can I do this? Thanks!

   
The devil is in the Details  -section of help(cat):

 Other types of R object should be converted
 (e.g. by 'as.character' or 'format') before being passed to 'cat'. 

 cat(VAR: , factor(a), \n)
VAR:  1
 cat(VAR: , format(factor(a)), \n)
VAR:  a
 cat(VAR: , as.character(factor(a)), \n)
VAR:  a


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Concatenate a Variable

2008-02-01 Thread Marc Schwartz
Carla Rebelo wrote:
 Good morning!
 
 I do not speak English very well and so I will try to explain the best I 
 can. I have this:
 
   tabela[,1]
 [1] a a b b a c b a c c c c c
 Levels: a b c
 
  unique(tabela[,1])
 [1] a b c
 Levels: a b c
 
  var-unique(tabela[,1])[1]
 
   var
 [1] a
 Levels: a b c
 
 But if I concatenate like this
   cat(VAR: , var, \n)
 
 I obtain
  VAR:  1
 
 and I want to obtain
  VAR: a
 
 How can I do this? Thanks!

'a' is a factor, thus you are getting the underlying numeric code as the
output.

Note from ?cat:

Currently only atomic vectors (and so not lists) and names are handled.
Character strings are output ‘as is’ (unlike print.default which escapes
non-printable characters and backslash — use encodeString if you want to
output encoded strings using cat). Other types of R object should be
converted (e.g. by as.character or format) before being passed to cat.


Thus:

var - factor(a, levels = c(a, b, c))

 var
[1] a
Levels: a b c

 is.vector(var)
[1] FALSE


So 'var' is not an atomic vector and you must therefore coerce it to a
character vector using as.character() before passing it to cat():

 cat(VAR: , as.character(var), \n)
VAR:  a


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Concatenate a Variable

2008-02-01 Thread John Kane
R is treating tablea[,1] as a factor.  Try converting
it to character.

--- Carla Rebelo [EMAIL PROTECTED] wrote:

 Good morning!
 
 I do not speak English very well and so I will try
 to explain the best I 
 can. I have this:
 
   tabela[,1]
 [1] a a b b a c b a c c c c c
 Levels: a b c
 
  unique(tabela[,1])
 [1] a b c
 Levels: a b c
 
  var-unique(tabela[,1])[1]
 
   var
 [1] a
 Levels: a b c
 
 But if I concatenate like this
   cat(VAR: , var, \n)
 
 I obtain
  VAR:  1
 
 and I want to obtain
  VAR: a
 
 How can I do this? Thanks!
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained,
 reproducible code.
 



  Looking for the perfect gift? Give the gift of Flickr!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.