ithin the single variable.
e.g. dat1$var1[6:10]<-dat1$var[5:9]
A.K.
- Original Message -
From: Ernie Tedeschi
To: r-help@r-project.org
Cc:
Sent: Saturday, July 7, 2012 11:20 PM
Subject: [R] Notation for previous observation in a data frame
I've created a data frame in R, but
Hi Ernie,
I'll use the built in mtcars dataset for demonstrative purposes.
You have some condition, which can be used to create an index
## show data frame
mtcars
## create index based on your condition
i <- which(mtcars$carb == 1)
## set those rows of mtcars in your index
## to the index - 1
mt
I've created a data frame in R, but in order to clean up some of the data,
I need to set certain variable observations equal to the value of their
previous observation (it would be conditional, but that part's less
important right now). In Stata, I would simply set var = var[_n-1] in those
cases. W
3 matches
Mail list logo