Displaying 20 results from an estimated 10000 matches similar to: "from character to numeric over multiple columns"
2007 Feb 19
1
memory management uestion
Hi All,
I would like to ask the following.
I have an array of data in an objetct, let's say X.
I need to use a for loop on the elements of one or more columns of X and I am
having a debate with a colleague about the best memory management.
I believe that if I do:
col1 = X[,1]
col2 = X[,2]
...
colx = X[,x]
and then
for(i in whatever){
do something using col1[i], col2[i] ... colx[i]
}
2006 Feb 28
4
subsetting a list of matrices
Hi All,
I have a list of matrices:
> x
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> y
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 18 21 24 27 30 33
[2,] 19 22 25 28 31 34
[3,] 20 23 26 29 32 35
> z =list(x,y)
I want to create a second list that is has a subset each matrix in the
list subsetting so I get the 2nd and 3rd row of each (and
2006 Mar 28
2
as.matrix and one row
Hi All,
I have the following problem:
x = c(1,2)
x
[1] 1 2
as.matrix(x)
[,1]
[1,] 1
[2,] 2
BUT, if I add:
y = c(3,4)
as.matrix(rbind(x,y))
[,1] [,2]
x 1 2
y 3 4
It does not transpose. Since I will need as.matrix() for a list of data
that is in one or more lines, I need as.matrix to behave in a consisten
fashions, so I get
as.matrix(x, whatever)
[,1] [,2]
x 1
2006 Jun 07
3
smoothing plot(x, type ='l')
Hi All,
I am using plot(x, type = 'l') for some plotting, but I would like rounded edges
rather than jagged edges in the plot (purely for aestetic reasons).
How could I achieve that?
Cheers,
Federico
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG
Tel +44 (0)20 7594 1602 Fax (+44) 020
2007 Jun 26
2
fisher information matrix
Hi All,
a colleague wants to calculate the Fisher information matrix for a model he
wrote (not in R). He can easily get the neg-log-likelihood and the best fit
parameters at the minimum. He can also get negLLs for other parameter values too.
Given these data, is there a way in R to calculate the Fisher information matrix?
Best,
Federico
--
Federico C. F. Calboli
Department of Epidemiology
2007 Jun 25
3
fractional calculations
Hi All,
is there a function in R that allows me to work with fractions without
transforming them to floats (or whatever) in between?
Something that would calculate something like:
(1/2 + 1/8) * 1/2 = 5/16
without ever transforming to 0.5 and 0.125?
Best,
Federico
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place,
2006 Apr 21
2
forcing apply() to return data frame
Hi All,
I am (almost) successfully using apply() to apply a function recursively
on a data matrix. The function is question is as.genotype() from the
library 'genetics'
apply(subset(chr1, names$breed == 'lab'),2,as.genotype,sep ="")
Unfortuantely apply puts it's results into a matrix object rather than a
data frame, tranforming my factors into numerics and
2006 Oct 26
2
pairs matchning
Hi
You could try to find an equivalent representation as a string and try to
match those.
> (A <- cbind(sample(1:2, 10, rep=TRUE), sample(1:2, 10, rep=TRUE)))
[,1] [,2]
[1,] 1 2
[2,] 1 2
[3,] 1 2
[4,] 2 2
[5,] 1 1
[6,] 1 2
[7,] 1 2
[8,] 1 1
[9,] 1 2
[10,] 1 1
> (B <- unique(A))
[,1] [,2]
[1,] 1 2
2006 Mar 12
1
finding warning point in function
Hi everyone,
I would like to find out when and where exactly I get the following
warning in a piece of code I've written:
Error in "[<-"(`*tmp*`, iseq, value = numeric(0)) :
nothing to replace with
The code is a for () loop performing a somewhat trivial calculation,
modulated by a number of logical if(){} else(){} conditions, involving
the creation of a number of
2006 May 22
3
writing 100 files
Hi All,
I need to write as text files 1000 ish variation of the same data frame,
once I permute a row.
I would like to use the function write.table() to write the files, and
use a loop to do it:
for (i in 1:1000){
bb8[2,] = sample(bb8[2,])
write.table(bb8, quote = F, sep = '\t', row.names = F, col.names = F,
file = 'whatever?????.txt')
}
so all the files are called
2005 Apr 05
2
cat bailing out in a for loop
Dear All,
I am trying to calculate the Hardy-Weinberg Equilibrium p-value for 42
SNPs. I am using the function HWE.exact from the package "genetics".
In order not to do a lot of coding "by hand", I have a for loop that
goes through each column (each column is one SNP) and gives me the
p.value for HWE.exact. Unfortunately some SNP have reached fixation and
HWE.exact requires a
2005 Mar 08
5
removing message: [Previously saved workspace restored]
Dear All,
I saved by mistake the environment I was working in after typing q(),
and now I get the annoying message:
[Previously saved workspace restored]
I have already deleted all the objects in the environment, saving it as
an empty environment, so it's just a matter of nitpicking I suppose. The
message does not appear if I start R from any other place in the
directory tree.
I am
2005 Apr 18
1
Rd.sty problems.
Hi All,
I am trying to build a new R package to submit, but it's failing to
create a tex manual:
R CMD check Biodem
* checking for working latex ... OK
* using log directory
'/home/greatsage/Fede/R-packages/temp/Biodem.Rcheck'
* checking for file 'Biodem/DESCRIPTION' ... OK
* checking if this is a source package ... OK
* Installing *source* package 'Biodem' ...
** R
2006 Mar 08
3
'less' for R?
Hi All,
is there an equivalent of the Unix command 'less' (or 'more'), so I can
look at what's inside a data.frame or a matrix without having it printed
out on console?
I am using R on Debian Linux and Mac OS 10.4.5
Cheers,
F
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG
Tel +44
2005 Apr 12
2
R as programming language: references?
Hi All,
I am looking for references on R as a programming language (apart form
the standard R-lang.pdf and the other manuals), reference that would
cover _in_depth_ things like loops, code optimisation, debugging tools
etc... and is as up-to-date as possible.
Can anyone suggest any book or other reference apart from the "green
book" and the V&R "S-programming"?
Cheers,
2008 May 08
3
lme nesting/interaction advice
Hi everyone,
I am confused on how to specify some nesting and interaction terma with lme().
I have a dataset where some flies where selected for accessory gland size, made
to mate in presence/absence of another male and the level of some protein
measured. Now the complex stuff.
The selection has been replicated twice, so that the selection term has got two
levels (large and small) with
2006 Nov 21
2
keeping dim() for array
Hi All,
I noticed the following:
pip = array(1:6, dim = c(3,2))
dim(pip)
[1] 3 2
pup = pip[1,]
dim(pup)
NULL
I bet there is a *good* reason why one row of an array is *dimensionless*, but
it's highly inconvenient for my purpose, i.e. to use apply() after an array goes
through a number of logical steps and is redimensioned, sometimes to one single row.
How do I keep dim(pup) to 1 2?
2005 Jul 21
3
vectorising ifelse()
Hi All,
is there any chance of vectorising the two ifelse() statements in the
following code:
for(i in gp){
new[i,1] = ifelse(srow[i]>0, new[srow[i],zippo[i]], sample(1:100, 1,
prob =Y1, rep = T))
new[i,2] = ifelse(drow[i]>0, new[drow[i]>0,zappo[i]], sample(1:100,
1, prob =Y1, rep = T))
}
Where I am forced to check if the value of drow and srow are >0 for each
line... in
2006 May 04
2
data manipulation docs
Hi All,
Is there some document/manual about data manipulation within R that I
could use as a reference (obviously, aside the R manuals)?
The reason I am asking is that I have a number of data frames/matrices
containg genetic data. The data is in a character form, as in:
V1 V2 V3 V4 V5
1 AA AG AA GG AG
2 AC AA AA GG AG
3 AA AG AA GG AG
4 AA AA AA GG AG
5 AA AA AA GG AA
I need, to chop,
2009 Nov 10
1
when vectorising does not work: silent function fail?
Dear All,
I'm using apply to do some genetic association analysis along a chromosome, with
many thousands markers. For each marker the analysis is the same, so I was
planning to use apply(chrom, 2, somefunction)
In the specific case I do:
my.results = apply(chr, 2, function(x){anova(lrm( cpstc.f ~ x + time.cpstc + age
+ sex + mri))[1,3]})
This is all good and well in theory, but in