You can easily achieve this using dplyr. So you will group_by the subject.id and filter by the count. So in this example, it would simply be: library(dplyr) subject.id <- c( 0, 0, 0, 1, 1, 1, 2, 2, 3 ) visit <- c( 0, 1, 2, 0, 1, 2, 0,...

Assuming these are all stored in a data.frame called dd then you could do plot(V2~Date, data=subset(dd, V1=="A")) That should produce a plot for all the "A" values in V1....

The Pesaran statistic will (asymptotically) follow a standard normal distribution if the null-hypothesis is true, so: the p-value is 2*(normal(-abs(r(pesaran))))

Something like this? pdf[!ave(pdf$obs, pdf$id, FUN = function(x) length(unique(x)) != 1), ] # id time obs # 2-1 2 1 1 # 2-2 2 2 1 # 2-3 2 3 1 # 4-1 4 1 0 # 4-2 4 2 0 # 4-3 4 3 0 ...

I found a solution myself using varfun: A = table(sort([repmat([1;2],4,1);repmat(3,3,1)]),[repmat((1994:1997).',2,1);(1995:1997).'],normrnd(100,1,11,1)) B = varfun(@(x)lagmatrix(x,1),A,'GroupingVariables','Var1') ...

How about cbind(mydata, date=allweeks[cumsum(mydata$Pos==1)]) Here we just grab the next date each time Pos=1 (assuming that indicates a new week value). -- Actually it looks like your row.names might have the numbers 1...40 but you can't have duplicate row names so I'm not sure what indicates a new week. So...

For your first question: This'll get the running sum for years that are not necessarily in the dataset as well (as you requested just underneath the two points). The idea is to first generate all combinations of event and year - even the ones which doesn't exist in the dataset....

dat <- read.table(text="Patient ID,Disease Score 101,5 101,2 101,2 105,1 110,5 115,1 115,1", stringsAs=FALSE, header=TRUE, sep=",") # one way in base dat[dat$Patient.ID %in% names(which(table(dat$Patient.ID)>2)),] # one way in dplyr library(dplyr) dat %>% group_by(Patient.ID) %>% mutate(n=n()) %>% ungroup() %>% filter(n>=2) %>% select(Patient.ID, Disease.Score) ...

Quite easy using either tidyr or reshape2. IMHO, every R user should learn to use these 2 packages along with data.table,dplyr. library("datasets") library(reshape2) library(dplyr) WorldPhones <- data.frame(WorldPhones) # matrix format to data.frame WorldPhones$Year <- rownames(WorldPhones) # create Year column df_1 <- df_2 <- df_3 <- WorldPhones # # transform to...