[R] lapply() not converting columns to factors (no error message)

David Winsemius dwinsemius at comcast.net
Mon Nov 16 14:17:55 CET 2009


Didn't you notice the difference between Sundar's code and yours?  
Sundar put the data.frame name before the column name while you did  
not do so in your check step.

-- 
DW


On Nov 16, 2009, at 8:07 AM, A Singh wrote:

> Oh, strange!
>
> I thought it might be a problem with the 'base' package  
> installation, because the same thing's worked for me too before but  
> won't do now.
>
> I tried to reinstall it (base), but R says its there already which I  
> expected it to be anyway.
>
> I don't quite know where the issue is. Very odd.
>
>
> --On 16 November 2009 04:59 -0800 Sundar Dorai-Raj <sdorairaj at gmail.com 
> > wrote:
>
>> Works for me:
>>
>> x <-
>> read.csv(url("http://dc170.4shared.com/download/153147281/a5c78386/Testvc
>> omp10.csv?tsid=20091116-075223-c3093ab0")) names(x)
>> x[2:13] <- lapply(x[2:13], factor)
>>
>>> levels(x$P1L55)
>> [1] "0" "1"
>>> is.factor(x$P1L96)
>> [1] TRUE
>>
>>> sessionInfo()
>> R version 2.10.0 (2009-10-26)
>> i386-apple-darwin9.8.0
>>
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] lattice_0.17-26
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.10.0  tools_2.10.0
>>
>> On Mon, Nov 16, 2009 at 4:50 AM, A Singh <Aditi.Singh at bristol.ac.uk>
>> wrote:
>>> Sorry, my file is at:
>>>
>>>
>>> http://www.4shared.com/file/153147281/a5c78386/Testvcomp10.html
>>>
>>>
>>> ----------------------
>>> A Singh
>>> Aditi.Singh at bristol.ac.uk
>>> School of Biological Sciences
>>> University of Bristol
>>>
>>> ______________________________________________
>>> 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.
>>>
>
>
>
> ----------------------
> A Singh
> Aditi.Singh at bristol.ac.uk
> School of Biological Sciences
> University of Bristol
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list