Hello R - users,
This may sound simple to may people:
I have a list of data as follows
type value
y 7
y 7
y 8
y 8
y 8
y 9
y 9
y 9
y 9
y 10
y 10
y 10
y 10
y 11
y 11
y 12
y 12
y 14
y 14
y 14
y 15
y 17
y 20
y 20
y 20
y 20
y 25
y 25
y 25
x 7
x 7
x 8
x 8
x 9
x 9
x 11
x 11
x 11
x 12
x 12
x 12
x 13
x 13
x 15
x 15
x 15
x 18
x 20
x 30
x 30
Is there any way where I can group all the x and y like
a <- all the values of x
b <- all the values of y
so 'a' will have = 7, 7, 8....
'b' = 7,7,8,8,8...
With Regards
Subhabrata Pal
Set Data the data frame of your data, it is straightforward to define x and y by R> x <- Data[Data$type=="x",-1] R> y <- Data[Data$type=="y",-1] Best regards,, Kristel Subhabrata wrote:> Hello R - users, > > This may sound simple to may people: > > I have a list of data as follows > > type value > y 7 > y 7 > y 8 > y 8 > y 8 > y 9 > y 9 > y 9 > y 9 > y 10 > y 10 > y 10 > y 10 > y 11 > y 11 > y 12 > y 12 > y 14 > y 14 > y 14 > y 15 > y 17 > y 20 > y 20 > y 20 > y 20 > y 25 > y 25 > y 25 > x 7 > x 7 > x 8 > x 8 > x 9 > x 9 > x 11 > x 11 > x 11 > x 12 > x 12 > x 12 > x 13 > x 13 > x 15 > x 15 > x 15 > x 18 > x 20 > x 30 > x 30 > > Is there any way where I can group all the x and y like > > a <- all the values of x > b <- all the values of y > > so 'a' will have = 7, 7, 8.... > 'b' = 7,7,8,8,8... > > > With Regards > Subhabrata Pal > > ______________________________________________ > 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-- __________________________________________ Kristel Joossens Ph.D. Student Research Center ORSTAT K.U. Leuven Naamsestraat 69 Tel: +32 16 326929 3000 Leuven, Belgium Fax: +32 16 326732 E-mail: Kristel.Joossens at econ.kuleuven.be http://www.econ.kuleuven.be/public/ndbae49 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
On 12/9/05 7:19 AM, "Subhabrata" <subhabratapal at sraindia.com> wrote:> > Hello R - users, > > This may sound simple to may people: > > I have a list of data as follows > > type value > y 7 > y 7 > y 8 > y 8 > y 8 > y 9 > y 9 > y 9 > y 9 > y 10 > y 10 > y 10 > y 10 > y 11 > y 11 > y 12 > y 12 > y 14 > y 14 > y 14 > y 15 > y 17 > y 20 > y 20 > y 20 > y 20 > y 25 > y 25 > y 25 > x 7 > x 7 > x 8 > x 8 > x 9 > x 9 > x 11 > x 11 > x 11 > x 12 > x 12 > x 12 > x 13 > x 13 > x 15 > x 15 > x 15 > x 18 > x 20 > x 30 > x 30 > > Is there any way where I can group all the x and y like > > a <- all the values of x > b <- all the values of y > > so 'a' will have = 7, 7, 8.... > 'b' = 7,7,8,8,8...Look at ?split. vec <- c(1,2,3,4,5,10,11,12,13,14,15,16) myletters <- c(rep('a',5),rep('b',7)) mylist <- split(vec,myletters) mylist$a mylist$b Sean
If your data frame is X then
unstack(X, value ~ type)
gives you a list with x and y components. If you need
these as variables try attach(unstack(X, value ~ type))
or
with(unstack(X, value ~ type, {
... some computations ...
}
On 12/9/05, Subhabrata <subhabratapal at sraindia.com>
wrote:>
> Hello R - users,
>
> This may sound simple to may people:
>
> I have a list of data as follows
>
> type value
> y 7
> y 7
> y 8
> y 8
> y 8
> y 9
> y 9
> y 9
> y 9
> y 10
> y 10
> y 10
> y 10
> y 11
> y 11
> y 12
> y 12
> y 14
> y 14
> y 14
> y 15
> y 17
> y 20
> y 20
> y 20
> y 20
> y 25
> y 25
> y 25
> x 7
> x 7
> x 8
> x 8
> x 9
> x 9
> x 11
> x 11
> x 11
> x 12
> x 12
> x 12
> x 13
> x 13
> x 15
> x 15
> x 15
> x 18
> x 20
> x 30
> x 30
>
> Is there any way where I can group all the x and y like
>
> a <- all the values of x
> b <- all the values of y
>
> so 'a' will have = 7, 7, 8....
> 'b' = 7,7,8,8,8...
>
>
> With Regards
> Subhabrata Pal
>
> ______________________________________________
> 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
>