[R] how to complete this task on data management
Petr Pikal
petr.pikal at precheza.cz
Wed Aug 23 11:10:31 CEST 2006
Hi
I am not sure what you really want. If you try to preserve first part
of your objects just exclude them from operation e.g.
data[-(1:5),] will exclude first five rows from your dataframe.
However it is unclear what you want to do next. Instead of three
items you want only add one different?
data.frame(x=c(data[(1:5),],6))
or another vector
data.frame(x=c(data[(1:5),],some.other.data))
Following probably too complicated construction tells you which is
the position of the second value lower then some threshold (in this
case 3.5) in a vector.
which(diff(cumsum(diff(data<3.5)==1)<2)!=0)+2
HTH
Petr
On 23 Aug 2006 at 11:23, zhijie zhang wrote:
Date sent: Wed, 23 Aug 2006 11:23:03 +0800
From: "zhijie zhang" <epistat at gmail.com>
To: R-help at stat.math.ethz.ch
Subject: [R] how to complete this task on data management
> Dear friends,
> When i clean my dataset , i met a difficulty
> suppose my data set is :
> *> data<-data.frame(x=c(1:5,1,2,3))
> > data
> x
> 1 1
> 2 2
> 3 3
> 4 4
> 5 5*
> 6 1
> 7 2
> 8 3
> Now i need to add the data which are less than 3.5 at the bottom, not
> including the top data, so the results should be :
> x
> 1 1
> 2 2
> 3 3
> 4 4
> 5 5
> *6 6*
> I tried to use " data[data$x>3.5,]" to do it , but it also delete the
> first several numbers,* How to finish it ?* Thanks very much. -- Kind
> Regards, Zhi Jie,Zhang
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list