[R] factor or character

Rui Barradas ruipbarradas at sapo.pt
Tue Oct 23 23:03:15 CEST 2012


Hello,

I've just seen the error, you are _not_ searching for colnames in 
mod5.sig$snps. Corrected:

Selec = todos[ , colnames(todos) %in% mod5.sig$snps]

Hope this helps,

Rui Barradas
Em 23-10-2012 21:17, Silvano Cesar da Costa escreveu:
> Hi Rui,
>
>
> it doesn't work:
>
>> (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor<5e-8],
> stringsAsFactors=FALSE)))
>> str(mod5.sig)
> 'data.frame':	76 obs. of  1 variable:
>   $ snps: Factor w/ 220 levels "rs10058955_A",..: 89 59 88 73 40 35 97 55
> 87 204 ...
>> Selec = todos[ , colnames(todos) %in% mod5.sig]
>> head(Selec)
> data frame com 0 colunas e 6  linhas
>
>
> the problem is the same.
>
> Thanks,
>
>
>
>
>> Hello,
>>
>> When creating the data.frame of snps use the option stringsAsFactors =
>> FALSE
>> I believe your error comes from the fact that you are trying to find
>> colnames in a variable coded as integers (a factor, like str shows).
>>
>> Hope this helps,
>>
>> Rui Barradas
>> Em 23-10-2012 19:02, Silvano Cesar da Costa escreveu:
>>> Hi,
>>>
>>> The program below work very well.
>>>
>>> (snps = c('rs621782_G', 'rs8087639_G', 'rs8094221_T', 'rs7227515_A',
>>> 'rs537202_C'))
>>> Selec = todos[ , colnames(todos) %in% snps]
>>> head(Selec)
>>>
>>>
>>> But, I have a data set with 1.000 columns and I need extract 70 to use
>>> (like snps in command above).
>>>
>>> This 70 snps are in a file. So I create a file to extract them with
>>>
>>> (mod5.sig = with(mod5, data.frame(snps = SNP[pvalor < 5e-8])))
>>> str(mod5.sig)
>>> (snps = (mod5.sig))
>>>
>>> The structure is:
>>> 'data.frame':	76 obs. of  1 variable:
>>>    $ snps: Factor w/ 220 levels "rs10058955_A",..: 89 59 88 73 40 35 97
>>> 55
>>> 87 204 ...
>>>
>>> But it doesn't work. The output is:
>>>> Selec = todos[ , colnames(todos) %in% snps]
>>>> head(Selec)
>>> data frame with 0 columns and 6 rows
>>>
>>> What's is wrong?
>>>
>>> Thanks a lot,
>>>
>>>
>>> ---------------------------------------------
>>> Silvano Cesar da Costa
>>>
>>> Universidade Estadual de Londrina
>>> Centro de Ciências Exatas
>>> Departamento de Estatística
>>>
>>> Fone: (43) 3371-4346
>>>
>>> ______________________________________________
>>> 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.
>>
>>
>
> ---------------------------------------------
> Silvano Cesar da Costa
>
> Universidade Estadual de Londrina
> Centro de Ciências Exatas
> Departamento de Estatística
>
> Fone: (43) 3371-4346
> ---------------------------------------------
>




More information about the R-help mailing list