[R] Display the character variables in a dataset in R
baptiste auguie
baptiste.auguie at googlemail.com
Mon Aug 17 11:05:13 CEST 2009
Hi,
If you have a data.frame, perhaps this can help,
tc = textConnection("carat cut color clarity depth table price x y z
1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63
5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
6 0.24 'Very Good' J VVS2 62.8 57 336 3.94 3.96 2.48")
h = read.table(tc,head=T)
close(tc)
str(h)
'data.frame': 6 obs. of 10 variables:
$ carat : num 0.23 0.21 0.23 0.29 0.31 0.24
$ cut : Factor w/ 5 levels "Fair","Good",..: 5 4 2 4 2 3
$ color : Factor w/ 7 levels "D","E","F","G",..: 2 2 2 6 7 7
$ clarity: Factor w/ 8 levels "I1","SI2","SI1",..: 2 3 5 4 2 6
$ depth : num 61.5 59.8 56.9 62.4 63.3 62.8
$ table : num 55 61 65 58 58 57
$ price : int 326 326 327 334 335 336
$ x : num 3.95 3.89 4.05 4.2 4.34 3.94
$ y : num 3.98 3.84 4.07 4.23 4.35 3.96
$ z : num 2.43 2.31 2.31 2.63 2.75 2.48
h[ , !sapply(h[2,], is.numeric)]
cut color clarity
1 Ideal E SI2
2 Premium E SI1
3 Good E VS1
4 Premium I VS2
5 Good J SI2
6 Very Good J VVS2
HTH,
baptiste
2009/8/17 rajclinasia <raj at clinasia.com>:
>
> Hi everyone,
>
> After reading the external file into R it will become a R dataset. Now my
> querry is i want to dispaly only character variables from that dataset.
> please help me in this aspect. if possible send me the code. it will be very
> helpful for us.
>
> Thank you in Advance.
> --
> View this message in context: http://www.nabble.com/Display-the-character-variables-in-a-dataset-in-R-tp25002163p25002163.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>
--
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list