[R] delete rows
Sundar Dorai-Raj
sundard at pdf.com
Fri May 3 20:43:24 CEST 2002
Sonchawan,
I have an answer for your first question:
> I would like to know how to delete some rows?
> Suppose I have a large data frame look something like this:
>
> x1 x2 x3 ..............
> a 1 0.45
> b 1 0.41
> c 0 0.43
> a 1 0.39
> d 1 0.40
> e 0 0.41
> r 1 0.42
> a 0 0.46
> . . ..
>
> I would like to have another data frame which has all columns like the
> original one but if any rows have the same values in x1, then keep only the
> first row and delet the rest. Is it any way to make it look like this?
>
> x1 x2 x3 ..............
> a 1 0.45
> b 1 0.41
> c 0 0.43
> d 1 0.40
> e 0 0.41
> r 1 0.42
> . . ..
SOLUTION:
> df <- data.frame(x1=gl(4,2,labels=letters[1:4]),
+ x2=gl(2,4,labels=0:1),
+ x3=rnorm(8))
> df
x1 x2 x3
1 a 0 0.08317423
2 a 0 -1.10762737
3 b 0 0.71998683
4 b 0 -1.61450894
5 c 1 -0.07808250
6 c 1 0.36657481
7 d 1 0.26291955
8 d 1 -0.65862664
> aggregate(df$x3,list(x1=df$x1,x2=df$x2),function(x) x[1])
x1 x2 x
1 a 0 0.08317423
2 b 0 0.71998683
3 c 1 -0.07808250
4 d 1 0.26291955
>
>
> Another question is I downloaded data from Oracle database to R which looks
> like this:
> DATE,'yyyy,ww' TRD_AMT
> 1 2001,01 57.99330
> 2 2001,01 59.52926
> 3 2001,03 61.31018
> 4 2001,04 59.07095
> 5 2001,05 62.29583
> 6 2001,06 63.96679
>
> It's weekly data and I would like to plot it. How could I do that?
>
Can't help you with the second one off the top of my head.
Sundar
--
Sundar Dorai-Raj, Ph.D.
Statistical Methods Engineer
PDF Solutions, Inc.
Richardson TX
(972) 889-3085 x216
(214) 392-7619 cell
sundard at pdf.com
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list