Displaying 20 results from an estimated 206 matches for "timevar".
Did you mean:
timeval
2012 Mar 20
2
Reshaping data from long to wide without a "timevar"
Hello All,
I was wondering if it's possible to reshape data from long to wide in R without using a "timevar". I've pasted some sample data below along with some code. The data are sorted by Subject and Drug. I want to transpose the Drug variable into multiple columns in alphabetical order.
My data have a variable called "RowNo" that functions almost like a "timevar" but not...
2011 Jul 04
2
I need help for creating a "timevar"
Hi all!
I have data in ?Long? format which I would like to reshape to ?Wide?. I know
that one possibility is the ?reshape? command, which needs a ?timevar?.
Data look as follows: There are approx. 3000 persons (?IDENTITY?) and, for
each person, there are between 2 and 20 events (?EVENT?). For now, there's
one row for each event (9506 rows)
http://r.789695.n4.nabble.com/file/n3643658/Screenshot-2.png
What is missing is the ?timevar? (SPSS cal...
2008 Sep 27
2
reshape "Error in data[, timevar] : incorrect number of dimensions"
...waves of a survey given to students at various middle
schools and high schools, with student id numbers for each student. I
am having difficulty reshaping the file from long to wide.
My code is below:
library(foreign)
svy <- read.spss("studsur4.SAV")
svy.wide <- reshape(svy, timevar="WAVE", idvar="id", direction="wide")
"id" is the student identification number, and "WAVE" takes values 1
and 2. I get the following error:
Error in data[, timevar] : incorrect number of dimensions
I would provide reproducible code but I can&...
2005 Feb 26
1
reshape without timevar argument?
...one ID and has as many columns as different
descriptions.
I have used a very convoluted step, but I'm very convinced there is
an easier way to do this.
Basically, I used the reshape function, but even in this convulated
way there is a step that I can't solve. I used a "fake" timevar using
the table function.
df <- data.frame(id=c(rep('IDa',3), rep('IDb', 5), rep('IDc', 2),
rep('IDd',5)), let=letters[1:5])
#add Freq to each id
xFreqdf <- merge(df, table(df['id']), by.x='id', by.y='Var1')
xFreq &...
2005 Aug 14
1
Panel data handling (lags, growth rates)
...this.
# Task: For a supplied list of variables (the list `lagvars'),
# make new columns in a dataset denoting lagged values.
# You must supply `unitvar' which identifies the unit that's
# repeatedly observed.
# You must supply the name of the time variable `timevar'
# and you must tell a list of the lags that interest you (`lags')
# Example:
# paneldata.lags(A, "person", "year", c("v1","v2"), lags=1:4)
paneldata.lags <- function(X, unitvar, timevar, lagvars, lags=1) {
stopifnot(length(lagvars)>=1)...
2009 Sep 14
2
problems with reshape
...XXXXX 2000-11-28
3 1043 2 56849XXXXXX QPWOER52E2XXXXXX 2000-07-07
4 1508 2 54982XXXXXX FJKLSD67P4XXXXXX 2000-12-12
5 1532 2 56849XXXXXX QWERTG50T0XXXXXX 2000-03-30
6 3283 1 12345XXXXXX POIQWE74H0XXXXXX 1999-12-31
Sil_cf and sil_pi are the idvar (sensible data too), prog is the timevar (now dataset is not sorted)
> sapply(rl, class)
id_rl prog sil_pi sil_cf sil_dat_avv
"integer" "integer" "character" "character" "Date"
> apply(rl, 2, function(x) sum(duplicated(x)))
id_rl prog...
2007 May 09
1
Errors with systemfit package and systemfitClassic()
...error message after using the sysfit package's function 'systemfitClassic':
Error in data[[eqnVar]] : subscript out of bounds
When I do this:
MSYS1 <- cbind(Y, Num, F, PO, PD, GO, GD)
MigOLS1 <- systemfitClassic("OLS", F ~ PO + PD + GO + GD, eqnVar = "Num", timeVar = "Y", data = MSYS1)
and I get this error message:
Error in inherits(x, "factor") : attempt to select more than one element
when I do this (removing quotes from columns set as 'eqnVar' and 'timeVar'):
MSYS1 <- cbind(Y, Num, F, PO, PD, GO, GD)
MigOLS1 <-...
2006 Jan 22
6
Making a markov transition matrix
...,"f1","f1","f1","f2","f2","f2","f2"),
year=c(83, 84, 85, 86, 83, 84, 85, 86),
state=sample(1:3, 8, replace=TRUE)
)
# Shift to wide format --
fixedup <- reshape(raw, timevar="year", idvar="name", v.names="state",
direction="wide")
# Now tediously build up records for an intermediate data structure
try <- rbind(
data.frame(prev=fixedup$state.83, new=fixedup$state.84),
data.frame(prev...
2008 Feb 10
2
reshape
...uot;a3", "a3", "a4", "a4", "a4", "a5",
"a5", "a6")
dat <- data.frame(id=1:12, sp=sp, tr=tr, val=31:42, code=code)
and below is what I'd like to obtain. That is, I'd like the tr
variable in different columns (as a timevar) with their value (val).
sp code tr.A tr.B tr.C
a a1 31 NA NA
a a2 NA 32 NA
a a2 NA 33 NA **
a a3 NA NA 34
b a3 35 36 NA
b a4 NA NA 37
c a4 38 NA NA
d a4 39 NA NA
d a5 NA 40 41
d a6 NA...
2009 Oct 04
2
Row to Column help
...A NA
2 k act dbt other calpas NA
3 l act act wai itas other
I tried:
> wide <- reshape(data, idvar=c("id","author"), direction="wide")
Error in `[.data.frame`(data, , timevar) : undefined columns selected
If I specify all columns, it gives the following format (which is not
desired):
wide <- reshape(data, idvar=c("id","author"),
+ direction="wide", *v.names="tmt", timevar="alliance"*)
> wide
id author tmt.wai...
2007 Dec 13
1
creating lagged variables
...1 -0.56047565
2 1 2 -0.23017749
3 1 3 1.55870831
4 2 1 0.07050839
5 2 2 0.12928774
6 2 3 1.71506499
I want to compute the lagged variable 'value(t-1)', taking subject id
into account.
My current effort produced the following:
##
my_lag <- function(dt, varname, timevarname='time', lag=1) {
vname <- paste(varname, if(lag>0) '.' else '', lag, sep='')
timevar <- dt[[timevarname]]
dt[[vname]] <- dt[[varname]][match(timevar, timevar + lag)]
dt
}
lag_by <- function(dt, idvarname='id', ...)
do.call(rbind, by(d...
2014 Mar 15
0
allocation error and high CPU usage from kworker and migration: memory fragmentation?
...eduction_function and lapply. I keep
reassigning to move to try to indicate to R that it can gc the previous
object referenced by move.
library(data.table)
library(lubridate)
# imports several data.tables, total 730 MiB
load(UPC) # provides PL_flag data.table
load(STORES) # and parent data.table
timevar = 'month'
by=c('retailer', 'month')
save.dir='/tmp/R_cache'
each.parent <- rbindlist(lapply(sort(list.files(MOVEMENT, full.names=T),
reduction_function, upc=PL_flag,
parent=parent, timevar=t...
2003 Oct 30
1
Trouble reshaping some data
...this:
t1 <- data.frame(id=c(1,1,2,2),
aspect=c("A","B","A","B"), score=c(10,9,11,12))
I'd like it to look like this:
id A B
1 10 9
2 11 12
reshape() looks like a good candidate for this job but I'm
not really sure about the roles of timevar and idvar for
this dataframe. I tried
t2 <- reshape(t1, direction="wide", timevar=t1[,3],
idvar=t1[,2])
which is obviously ignorant and wrong.
Thank you in advance for any comments.
Regards,
Andrew C. Ward
CAPE Centre
Department of Chemical Engineering
The Univer...
2006 Jan 23
0
Making a markov transition matrix - more progress
...,"f1","f1","f1","f2","f2","f2","f2"),
year=c(83, 84, 85, 86, 83, 84, 85, 86),
state=sample(1:3, 8, replace=TRUE)
)
# Shift to wide format --
fixedup <- reshape(raw, timevar="year", idvar="name", v.names="state",
direction="wide")
# Now tediously build up records for an intermediate data structure
tmp <- rbind(
data.frame(prev=fixedup$state.83, new=fixedup$state.84),
data.frame(prev...
2008 Sep 10
3
(PR#12770) format() under Windows giv wrong resuts with
...is an Windows service that is being called. So there is no evidence at
all of any bug in R here.
On Wed, 10 Sep 2008, pego.enrico at tiscali.it wrote:
> Full_Name: Enrico Pegoraro
> Version: 2.7.2
> OS: Windows
> Submission from: (NULL) (87.4.187.101)
>
>
> The
> format(timevar,format="%I:%M:%S %p")
> instruction, with "timevar" a "POSIXt" "POSIXlt" variable, give wrong return
> data.
> The format sentence string "%I:%M:%S %p" requires times with AM/PM indicator,
> but the resulting output doesn't contain...
2010 Mar 06
1
transposing data
...s of all the levels of all the
independent variables.
For example, exp1.r5 is my data frame, Subject is the grouping
variable, I want to go from long to wide, the dependent variable is
RT, and I want to get RT as observed at each combination of each
level of all the variables listed in the timevar argument:
exp1.r5.wide <- reshape(exp1.r5, idvar="Subject", direction = "wide",
sep = "", v.names="RT", timevar = c("CannonAngle", "CannonOriB",
"CannonOriR", "nRedPellets", "TargetColor", "tbearin...
2008 Apr 24
1
re shaping "long-form" longitudinal data from sql query
...4000610 11/16/2004 10:39:51 1254 7.1 HGBA1C
...etc
I'd like to end up with a wide-format table like:
PID OBSDATE.1 DaysAgo.1 CleanValue.1 [...] OBSDATE.n DaysAgo.n
CleanValue.n
The problem: Every patient's on a different schedule, so there's no natural
timevar value to reshape with.
My solution involved creating another column for the timevar and looping
through the dataframe to populate that column with correct values; however,
it's a pretty big table and so the loop runs really slowly. I need to do
this particular operation on quite a few datafil...
2010 Jun 17
2
help for reshape function
...100
gene2 1 20 10
gene2 2 40 20
gene2 3 60 100
the column "gene" is required and column "tissue" is not needed. I use the
following syntax to perform this task:
tdata<- reshape(data, varying=names(data)[-c(1,2)],direction="long", timevar
="label",v.names="value",time=names(data)[-c(1,2)]);
however, i lose the column "gene" in the resulting tranposed dataset. I did
my best to go through the help doc for reshape. however, I am frustrated
that the examples used in the help doc is kind o hard to follow to...
2006 Feb 22
1
unused factor levels in reshape
...<- data.frame(i = factor(rep(1:5, each = 2)), t = factor(rep(1:2, 5)), x = rep(rbinom(5, 1, 0.5), each = 2), y = rpois(10, 10))
> subdf <- subset(df, i %in% 1:3)
defines a dataframe, and a subframe with some unused factor levels (i = 4, 5). Then
> reshape(df, v.names = "y", timevar = "t", idvar = "i", direction = "wide")
i x y.1 y.2
1 1 0 13 6
3 2 0 12 5
5 3 0 10 9
7 4 1 9 11
9 5 1 12 8
works fine but
> reshape(subdf, v.names = "y", timevar = "t", idvar = "i", direction = "wide")
Error...
2002 Oct 25
1
reshape: duplicate rows to multiple cols
...ape to have the pct.lgth value put into its corresponding
lulc col, e.g.
stream sumlength lulc.23 lulc.41 lulc.42 lulc.51 ...
1223030419686 4.73 0.05796068 15.85833341 56.02536998 15.01057082
I've tried:
>klam.wide <- reshape(klam.merge, varying=list(levels(klam.merge$lulc)), + timevar="stream",drop="x",direction="wide")
which yields
Error in "[<-.data.frame"(*tmp*, , varying[, i], value =
thistime[match(rval[, :
subscript out of bounds
In addition: There were 20 warnings (use warnings() to see them)
>
I've also tried...