Hello Everyone,

I am trying to create a subset of a data frame (df1) based on the first
three
unique values in the first column (v1).

Here are my codes:

b <- unique(df1$v1)[1:3]
df2 <- subset(df1,df1$v1==b)

df1:
v1   v2    v3
1     a    b
1     a1   b1
2     a2   b2
2     a3   b3
3     a4   b4
3     a5   b5
3     a6   b6
4     a7   b7
4     a8   b8
4     a9   b9
5     a10  b10
5     a11  b11
5     a12  b12
5     a13  b13


Ideally, I want my new dataframe (df2) to look something like this:


df2:
v1   v2    v3
1     a    b
1     a1   b1
2     a2   b2
2     a3   b3
3     a4   b4
3     a5   b5
3     a6   b6



However, that doesn't seem to be the case and i am getting the following
warning message:

Warning message:
In df1$v1==b :  longer object length is not a multiple of shorter object
length


I would appreciate any help in this regard,

sincerely,
bhaskar

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to