[R] delete rows

Thomas Lumley tlumley at u.washington.edu
Fri May 3 17:58:23 CEST 2002


On Fri, 3 May 2002, sonchawan tamkaew wrote:

> Hello,
>
> 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
> .        .       ..
>

If your data frame is called df then
  df<-subset(df,!duplicated(x1))
will do it.

>
> 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?

You probably want to convert the first column to a date. If it is a
factor, convert it to a string with as.character(), and then use
strptime() to convert it to a date. This requires specifying a weekday.
One possibility is
  strptime(paste(DATE,"1"),"%Y,%W %w")
which will give Mondays

	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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