[R] simple data.frame question
arun
smartpink111 at yahoo.com
Wed May 16 19:00:28 CEST 2012
Hi Troels,
Not sure this is what you want.
> X<-runif(9,0,10)
> FF1<-data.frame(ID=c(1,2,3)[rep(c(1,1,1,2,2,2,3,3,3))], PERIOD=c(1,2,3)[rep(c(1,2,3),times=3)],X=X)
> FF1$X[4]<-NA
> FF1
ID PERIOD X
1 1 1 8.27119347
2 1 2 9.64698097
3 1 3 2.74132386
4 2 1 NA
5 2 2 4.29322683
6 2 3 5.09269667
7 3 1 4.07936332
8 3 2 7.41808455
9 3 3 0.01558664
A.K.
----- Original Message -----
From: Troels Ring <tring at gvdnet.dk>
To: r-help at r-project.org
Cc:
Sent: Wednesday, May 16, 2012 11:56 AM
Subject: [R] simple data.frame question
Dear friends - I hope you will forgive me another simple question, illustrated by
ID <- c(1,1,1,2,2,3,3,3)
PERIOD <- c(1,2,3,2,3,1,2,3)
X <- runif(8,0,10))
FF <- data.frame(ID=ID,PERIOD=PERIOD,X=X)
I need to the fourth value of X as NA, and ID and PERIOD is updated to 1,1,1,2,2,2,3,3,3 and 1,2,3,1,2,3,1,2,3 respectively.
How do I use the pattern in ID and PERIOD to find the lacking X and put NA?
Best wishes
Troels Ring,
Aalborg, Denmark
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list