Skip to content

factor or character

6 messages · Silvano, Rui Barradas

#
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:
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
#
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 Rui,


it doesn't work:
stringsAsFactors=FALSE)))
'data.frame':	76 obs. of  1 variable:
 $ snps: Factor w/ 220 levels "rs10058955_A",..: 89 59 88 73 40 35 97 55
87 204 ...
data frame com 0 colunas e 6  linhas


the problem is the same.

Thanks,
---------------------------------------------
Silvano Cesar da Costa

Universidade Estadual de Londrina
Centro de Ci?ncias Exatas
Departamento de Estat?stica

Fone: (43) 3371-4346
#
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,

still doesn't work.
---------------------------------------------
Silvano Cesar da Costa

Universidade Estadual de Londrina
Centro de Ci?ncias Exatas
Departamento de Estat?stica

Fone: (43) 3371-4346
#
Hello,

Sorry but, what doesn't work? What is the error message or result?
As for stringsAsFactors not keeping character strings as character 
strings maybe this is from calling data.frame from within the 
environment used by with(), but you can use other ways of converting to 
character strings, such as

mod5.sig$snps <- as.character(mod5.sig$snps)

before subsetting. And you can also check the result of

colnames(todos) %in% mod5.sig$snp

What does this give you?

Hope this helps,

Rui Barradas
Em 24-10-2012 11:58, Silvano Cesar da Costa escreveu: