Displaying 20 results from an estimated 900 matches similar to: "produce variable on the fly"
2008 Jul 04
4
Re ad in a file - produce independent vectors
Is there a way of reading in a file in a way that each line becomes a vector:
for example:
meals.txt
breakfast bacon eggs sausage
lunch sandwich apple marsbar crisps
dinner chicken rice custard pie
I want to read in this file and end up with 3 different vectors, one called
breakfast which contains "bacon", "eggs", sausage" One called
2008 Aug 07
1
re order vector in order given by another vector
So imagine I have a vector:
zz = c("a","c","d","b")
and another vector:
xx = c("d","c","a","b")
I need to get xx in the same order as zz. I am sure this is very simple but
I can't figure it out from the help pages for order or sort. Perhaps I'm not
trying hard enough but its been bugging me for a while....
2008 Sep 22
1
Combine data frames using column names as "key"
Hi guys,
Suppose I have 2 data frames ie:
values
one 0.32
two 0.25
three 0.11
and
values
two 0.66
one 0.74
three 0.19
nb the first column is the row names in both cases
How can I combine them on the row names column? Ie to make something like
values.1 values.2
one 0.32 0.74
two 0.25 0.66
three 0.11 0.19
I guess its
2009 Dec 15
1
Changing Column names in (Output) csv file
Dear R helpers
Following is a part of R code.
data_lab <- expand.grid(c("R11", "R12", "R13"), c("R21", "R22", "R23"), c("R31", "R32", "R33"), c("R41", "R42", "R43"), c("R51", "R52", "R53"), c("R61", "R62", "R63"),
2010 Jan 25
5
Data transformation
Dear all,
I have a dataset that looks like this:
x <- read.table(textConnection("col1 col2
3 1
2 2
4 7
8 6
5 10"), header=TRUE)
I want to rewrite it as below:
var1 var2 var3 var4 var5 var6 var7 var8 var9 var10
1 0 1 0 0 0 0 0 0 0
0 2 0 0 0 0 0 0 0 0
0 0 0 1 0 0
2012 Jan 08
2
multivariate problem
Dear all,
I am not sure if this is the right place to ask this question, but I will have a go. Please redirect me to a different place if this is not the right one!
I have a (relatively) simple problem which causes me some frustration because I cannot find the solution. I measure ten variables (var1 to var10) every day, they are all continuous (linear) and most of them are correlated. Some days,
2010 Sep 30
1
Several Lattice plots in one Plot
Hi all,
I've been trying for hours, but I do not find a Solution. I want to plot 12 variables over time in separate diagrams in one plot/window using lattice. Two columns, six rows. I used print with the split command, but the graphics are getting really small. Can someone please help me.
Following data example:
dta = data.frame(
day=c(1,2,3,4,5,6,7),
2011 Nov 04
1
How to use 'prcomp' with CLUSPLOT?
Hello,
I have a large data set that has more columns than rows (sample data below). I am trying to perform a partitioning cluster analysis and then plot that using pca. I have tried using CLUSPLOT(), but that only allows for 'princomp' where I need 'prcomp' as I do not want to reduce my columns. Is there a way to edit the CLUSPLOT() code to use 'prcomp', please?
#
2012 Oct 25
1
cut point in ROC
var1
var2
var3
var4
var5
var6
var7
var8
var9
var10
gold
2
3
1
2
4
0
1
4
4
3
2
2
4
2
4
3
4
2
4
4
4
2
3
3
0
0
4
1
0
2
4
4
2
1
4
0
3
2
0
0
2
4
4
2
3
4
0
2
2
0
0
0
3
4
2
2
2
3
2
2
0
0
0
2
4
2
2
4
1
1
2
0
0
3
3
3
2
3
4
1
4
0
0
0
0
3
4
2
3
1
0
2
2
1
0
2
3
3
2
0
3
1
1
1
1
2
1
2
3
2
1
2004 Jan 08
1
(no subject)
Hello,
I have trouble converting a character string to a R object. Let me describe this by an example;
> dim(a)
[1] 270 14
> dim("a")
NULL
> names(a)
[1] "Var1" "Var2" "Var3" "Var4" "Var5" "Var6" "Var7" "Var8" "Var9"
[10] "Var10" "Var11" "Var12"
2011 Jan 21
3
nlminb doesn't converge and produce a warning
Hi Everybody,
My problem is that nlminb doesn't converge, in minimising a logLikelihood
function, with 31*6 parameters(2 weibull parameters+29 regressors repeated 6
times).
I use nlminb like this :
res1<-nlminb(vect, V, lower=c(rep(0.01, 12), rep(0.01, 3), rep(-Inf, n-15)),
upper=c(rep(Inf, 12), rep(0.99, 3), rep(Inf, n-15)), control =
list(maxit=1000) )
and that's the result :
2007 Nov 07
2
creating a dynamic output vector
Let's say I have a program that returns variables whose names may be any
string within the vector
NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), but I do
not ever know which ones have actually been created. So in one example
output, "varA", "varC", and "varD" could exist, but
2018 May 03
4
adding overall constraint in optim()
Hi ?
This is giving me a headache. I?m trying to do a relatively simple optimization ? actually trying to approximate the output from the Excel Solver function but at roughly 1000x the speed. ?
The optimization parameters look like this. The only trouble is that I want to add a constraint that sum(wgt.vect)=1, and I can?t figure out how to do that in optim.
Mo.vect <-
2006 Sep 04
3
Subsetting vectors based on condition
Hello,
I have a question regarding subsetting of vectors. Here's an example of
what I'm trying to do:
vect.1 <- c(76,195, 290, 380)
vect.2 <- c(63, 95, 133, 170, 215, 253, 285, 299, 325, 375)
I would like to subset vect.2 so that it has the same length as vect.1,
and its numbers are the first corresponging higher value compared to
vect.1.
The output should be:
final.output =
2003 Nov 14
7
Vector indices and minus sign
Hi,
I got caught out by this behaviour in 1.8.0 and I wondered why this
happens:
I have a list of vectors and was using lapply and grep to remove
matched elements that occur in only a subset of the elements of the
list:
locs <- lapply(locs, function(x){x[- grep("^x", x)]})
The problem is that where the grep finds no matches and hence returns a
vector of length 0, all the
2018 May 03
2
adding overall constraint in optim()
Thanks Bert. But everyone on that forum wants to use finance tools rather than general optimization stuff! And I am not optimizing a traditional Markowitz mean-variance problem. Plus, smarter people here. :-)
> On May 3, 2018, at 3:01 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> You can't -- at least as I read the docs for ?optim (but I'm pretty
> ignorant
2011 Feb 13
6
From numeric vector to string vector
Hi there, I have a numeric vector let say:
Vect <- c(12.234, 234.5675, 1.5)
Now I want a string vector like:
changedVec <- c("012.234", "234.568", "001.500")
Would be grateful if somebody help me how can I do that.
Thanks and regards,
[[alternative HTML version deleted]]
2008 Jun 09
1
Cross-validation in R
Folks; I am having a problem with the cv.glm and would appreciate someone
shedding some light here. It seems obvious but I cannot get it. I did read
the manual, but I could not get more insight. This is a database containing
3363 records and I am trying a cross-validation to understand the process.
When using the cv.glm, code below, I get mean of perr1 of 0.2336 and SD of
0.000139. When using a
2012 Dec 11
1
Rprof causing R to crash
I'm trying to use Rprof() to identify bottlenecks and speed up a particullary
slow section of code which reads in a portion of a tif file and compares
each of the values to values of predictors used for model fitting. I've
written up an example that anyone can run. Generally temp would be a
section of a tif read into a data.frame and used later for other processing.
The first portion
2012 Mar 17
3
rtriang using ifelse statement
Hi All,
I want to draw samples (n=4) from one of 2 triangular distributions for
each value in a matrix. I am using an ifelse statement to try to define
which distribution to draw from.
>From the output, I can see that the ifelse statement is choosing the correct
distribution, however, my n=4 simulations aren't occurring. Is there a way
to adjust the ifelse statement to fix this, or must