Displaying 20 results from an estimated 50000 matches similar to: "Refer to previous row"
2011 Jul 19
3
How to get predicted values of y for different x values?
Here is my model with interaction terms and control variables (I changed
variables names for easy read): 
reg1 <- lm(y ~ x1*x2*x3 +control1 + control2 + control3) 
x1 ranges from 0 to 6; x2 from 0 to 5; and x3 from 0 to 4. All three are
discrete ordinal variables; but I will treat them as continuous variables. 
(a) How can I see the predicted values of y for each of these scenarios (210
2013 Jan 09
4
Basic loop programming
Hi all,
newbie question: I am trying to set up a very simple loop without succeeding.
Let's say I have monthly observation of two variables for a year
- Sales_2012_01, Sales_2012_02, Sales_2012_03, ....      (total sales
for jan 2012,feb 2012, etc.)
- Customers_2012_01, Customers_2012_02, ....  (total number of
customers for jan 2012, etc.)
and I want to create new monthly variables in
2010 Mar 23
1
Conditional replacement of NA depending on value in the previous column
Dear R-helpers,
I have a dataframe like this:
ID  X1  X2  X3  X4  X5  X6
49  1   1   1   0   NA  NA
50  1   1   1   1   NA  1
I would like to convert a missing value (NA) that follows a 0 (zero) or
another missing value (NA) into a 0 (zero).
So, the above lines would be converted to:
ID  X1  X2  X3  X4  X5  X6
49  1   1   1   0   0   0
50  1   1   1   1   NA  1
I have been struggling with
2011 Jul 07
2
subset from a dataset after comparing its one column to a related vector
Hello R users,
I have two data sets like the following. Form of dataset:
data:
      X1       X2        X3    X4       X5
     1902       RE        3      594        9
      1903       RE        3     1340        7
      1904       AA        3      760       14
      1908       RE        4     1759       18
      1909       EX        2      387        1
      2901       AU        6     3116    
2012 Sep 12
3
how to create a substraction matrix (subtract a row of every column from the same row in other columns)
Hello
I have data like this
x1  x2  x3  x4  x5
I want to create a matrix similar to a correlation matrix, but with the
difference between the two values, like this
x1   x2         x3         x4          x5
x1   x2-x1    x3-x1     x4-x1     x5-x1
x2               x3-x2     x4-x2     x5-x2
x3                           x4-x3      x5-x3
x4                                        x5-x4
x5
Then I
2007 Jul 14
1
row names and identical
Below x1, x2 and x3 all have the same data and all have the same value
for row.names(x); however, the internal values of their row.names differ.
The internal value of row.names is c(NA, -4L) for x1, c(NA, 4L) for x2 and
c("1", "2", "3", "4") for x3; nevertheless, identical regards x1 and x2 as
identical while x3 is not identical to either of x1 or x2.
Is
2011 Feb 17
2
sort by column and row names
Hello, All,
How can one sort on column and row names.  For example:
How can this
X1   X3   X2
X1   1     0      0
X3   0     1      0
X2   0     0      1
become this?
X1   X2   X3
X1   1     0      0
X2  0     1      0
X3   0     0      1
Thank you for your time!
Jim
	[[alternative HTML version deleted]]
2011 Jan 31
2
Missing at random
R users:
Thanks in advance
 How to generate missing at random (MAR)?
assaedi76@yahoo.com
Thanks
      
	[[alternative HTML version deleted]]
2013 Apr 13
1
how to add a row vector in a dataframe
Hi,
Using S=1000
and
simdata <- replicate(S, generate(3000)) 
#If you want both "m1" and "m0" #here the missing values are 0
res1<-sapply(seq_len(ncol(simdata.psm1)),function(i) {x1<-merge(simdata.psm0[,i],simdata.psm1[,i],all=TRUE); x1[is.na(x1)]<-0; x1})
res1[,997:1000]
#????? [,1]???????? [,2]???????? [,3]???????? [,4]??????? 
#x1??? Numeric,3000 Numeric,3000
2012 Jul 24
5
First value in a row
Hi.
This is likely a trivial problem but have not found a solution.  
Imagine the following dataframe:
Lat   Lon  x1   x2  x3
01    10   NA   NA  .1
01    11   NA   .2  .3
01    12   .4   .5  .6
I want to generate another column that consist of the first value in  
each row from columns x1 to x3. That is
NewColumn
.1
.2
.4
Any input greatly appreciated,
Thanks,
Camilo
Camilo Mora, Ph.D.
2010 Nov 13
1
Define a glm object with user-defined coefficients (logistic regression, family="binomial")
Hi there,
I just don't find the solution on the following problem. :(
Suppose I have a dataframe with two predictor variables (x1,x2) and one 
depend binary variable (y). How is it possible to define a glm object 
(family="binomial") with a user defined logistic function like p(y) = 
exp(a + c1*x1 + c2*x2) where c1,c2 are the coefficents which I define. 
So I would like to do no
2011 Nov 30
3
how to call a function for each row
Hi
 I have  a data-frame which look like this
X1 X2 X3
1   3  5
2   4  6
3   6  1
I want to apply a formula Y=6*X1 + 7*X2 + 8*X3  for every row
Thanks in Advance
--
View this message in context: http://r.789695.n4.nabble.com/how-to-call-a-function-for-each-row-tp4122906p4122906.html
Sent from the R help mailing list archive at Nabble.com.
2005 Apr 22
3
as.data.frame: Error in "names<-.default" (PR#7808)
Hello,
I found a potential problem in R 2.1.0 (and R 2.0.1)
I expect that
> tmp <- FUN(x1, x2, x3, x4)
> as.data.frame(tmp)
is the same as
> as.data.frame(FUN(x1, x2, x3, x4))
since the tmp variable in this case is unnecessary.
However, below I will demonstrate that under an odd set of conditions, I
can correctly perform as.data.frame(tmp), but not as.data.frame(FUN(x1,
x2, x3,
2009 Oct 02
6
split-apply question
Hi,
I have a data frame that looks like this:
>x
x1  x2  x3
A   1    1.5
B   2    0.9
B   3    2.7
C   7    1.8
D   7    1.3
I want to "group" by the x1 column and in the case of multiple x$x1 values
(e.g., "B")d, return rows that have the smallest values of x2. In the case
of rows with only one value of x1 (e.g., "A"), return the row as is. How can
I do that? 
2012 Jul 12
3
Add row into a Matrix witout headers from Function
Hi,
Here i have a matrix like this,
OLDMatrix <-
X1         X2        X3
-----      ------    ------
22          24         23
25          27         27
10          13         15
the thing is,
im running two function(SUM,COUNT) to get output in another matrix called
NEWMatrix
NEWMatrix <- c("SUM",colSums(OLDMatrix ))
NEWMatrix  <- c("COUNT",colSums(!is.na(OLDMatrix
2006 Jul 08
2
String mathematical function to R-function
hello
I make a subroutine that give-me a (mathematical)
function in string format.
I would like transform this string into function ( R
function ).
thanks for any tips.
cleber
#e.g.
fun_String = "-100*x1 + 0*x2 + 100*x3"
fun <- function(x1,x2,x3){
return(
############
evaluation( fun_String )
############
)
True String mathematical function :-(  :-(
> nomes
[1]
2009 Jun 08
5
if else
Hi R-helpers!
I have the following dataframe:
firm<-c(rep(1:3,4))
year<-c(rep(2001:2003,4))
X1<-rep(c(10,NA),6)
X2<-rep(c(5,NA,2),4)
data<-data.frame(firm, year,X1,X2)
data
So I want to obtain the same dataframe with a variable X3 
that is:
X1, if X2=NA
X2, if X1=NA
X1+X2 if X1 and X2 are not NA
So my final data is
X3<-c(15,NA,12,5,10,2,15,NA,12,5,10,2)
2004 May 07
3
re-ordering a vector by name
Dear R-help,
Let's say `x1' and `x2' are very long vectors (length=5e5, say) with same
set of names but in different order.  If I want to sort `x2' in the order of
`x1', I would do 
  x2[names(x1)]
but the amount of time that takes is quite prohibitive!  Does anyone have
any suggestion on a more efficient way to do this?
If the two vectors are exactly the same length (as I
2009 Feb 25
3
indexing model names for AICc table
hi folks,
I'm trying to build a table that contains information about a series of 
General Linear Models in order to calculate Akaike weights and other 
measures to compare all models in the series.
i have an issue with indexing models and extracting the information 
(loglikehood, AIC's, etc.) that I need to compile them into the table. 
Below is some sample code that illustrates my
2017 Oct 12
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hi,
I recently ran into an inconsistency in the way model.matrix.default
handles factor encoding for higher level interactions with categorical
variables when the full hierarchy of effects is not present. Depending on
which lower level interactions are specified, the factor encoding changes
for a higher level interaction. Consider the following minimal reproducible
example:
--------------
>