Table collumn to single var in lowcase

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Table collumn to single var in lowcase

Milton Cezar
Dear All,
   
  I have read a table using
      DataTABLE <- read.table("mytable.txt, header=T)
   
  And get the following data structure
       Var1  VAR2   VaR3  Var4 ...
   
  How can I list all collumn names (in lowcase) and create variables from table collumns. By hand I do
      var1 <- DataTABLE$Var1
      var2 <- DataTABLE$VAR2
      var3 <- DataTABLE$VaR3
      var4 <- DataTABLE$Var4
   
  Unfortunatelly these data come as an output from other program and the data file have about 80 collumns.
   
  Thanks in advance!
   
  miltinho

 __________________________________________________


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Table collumn to single var in lowcase

Chuck Cleland
names(DataTABLE) <- tolower(names(DataTABLE))

?casefold
?names

Milton Cezar wrote:

> Dear All,
>    
>   I have read a table using
>       DataTABLE <- read.table("mytable.txt, header=T)
>    
>   And get the following data structure
>        Var1  VAR2   VaR3  Var4 ...
>    
>   How can I list all collumn names (in lowcase) and create variables from table collumns. By hand I do
>       var1 <- DataTABLE$Var1
>       var2 <- DataTABLE$VAR2
>       var3 <- DataTABLE$VaR3
>       var4 <- DataTABLE$Var4
>    
>   Unfortunatelly these data come as an output from other program and the data file have about 80 collumns.
>    
>   Thanks in advance!
>    
>   miltinho
>
>  __________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Table collumn to single var in lowcase

P Ehlers
In reply to this post by Milton Cezar
tolower(names(DataTABLE))

Peter Ehlers


Milton Cezar wrote:

> Dear All,
>    
>   I have read a table using
>       DataTABLE <- read.table("mytable.txt, header=T)
>    
>   And get the following data structure
>        Var1  VAR2   VaR3  Var4 ...
>    
>   How can I list all collumn names (in lowcase) and create variables from table collumns. By hand I do
>       var1 <- DataTABLE$Var1
>       var2 <- DataTABLE$VAR2
>       var3 <- DataTABLE$VaR3
>       var4 <- DataTABLE$Var4
>    
>   Unfortunatelly these data come as an output from other program and the data file have about 80 collumns.
>    
>   Thanks in advance!
>    
>   miltinho
>
>  __________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Table collumn to single var in lowcase

Gabor Grothendieck
In reply to this post by Milton Cezar
Note that creating separate variables out of your data frame is
not really a good idea.  However, to answer your question:

# this puts it on the path
iris.lc <- iris
names(iris.lc) <- tolower(names(iris.lc))
attach(iris.lc)
search() # shows where its located
print(head(sepal.length))
detach() # get rid of it
search() # now its not there


# this puts them right in the global environment
for(nm in names(iris))
        assign(tolower(nm), iris[[nm]], .GlobalEnv)
ls()
print(head(sepal.length))
rm(list = tolower(names(iris))) # remove them

Also note ?with which is probably preferred:

iris.lc <- iris
names(iris.lc) <- tolower(names(iris.lc))
with(iris.lc, {
  print(head(sepal.length))
  print(head(sepal.length+1))
})



On 6/2/06, Milton Cezar <[hidden email]> wrote:

> Dear All,
>
>  I have read a table using
>      DataTABLE <- read.table("mytable.txt, header=T)
>
>  And get the following data structure
>       Var1  VAR2   VaR3  Var4 ...
>
>  How can I list all collumn names (in lowcase) and create variables from table collumns. By hand I do
>      var1 <- DataTABLE$Var1
>      var2 <- DataTABLE$VAR2
>      var3 <- DataTABLE$VaR3
>      var4 <- DataTABLE$Var4
>
>  Unfortunatelly these data come as an output from other program and the data file have about 80 collumns.
>
>  Thanks in advance!
>
>  miltinho
>
>  __________________________________________________
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html