Re: [R] Newbie Question on making subsets for every element of a table column

2012-04-23 Thread Petr Savicky
On Mon, Apr 23, 2012 at 02:33:22PM -0700, cyclondude wrote:
> Yes. That is what I was looking for.  Is there a simple way to (in this
> scenario)
> 
> 
> > out[[1]]
> 
> v1 v2
>   1  a  1
>   4  a  2
>   7  a  3 
> 
> > a <- out[[1]]
> 
> for each one?

Hi.

If you want to generate variable names by a script, then try

  dat <- expand.grid(v1=letters[1:3], v2=1:3)
  for (var in unique(as.character(dat$v1))) {
  assign(var, subset(dat, v1 == var))
  }

  ls() # [1] "a"   "b"   "c"   "dat" "var"

  a

v1 v2
  1  a  1
  4  a  2
  7  a  3

  b

v1 v2
  2  b  1
  5  b  2
  8  b  3

Hope this helps.

Petr Savicky.

__
R-help@r-project.org 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.


Re: [R] Newbie Question on making subsets for every element of a table column

2012-04-23 Thread R. Michael Weylandt
There are, but it's generally considered better style to keep them all
in a single list and use lapply() if you want to do things to each
element.

Michael

On Mon, Apr 23, 2012 at 5:33 PM, cyclondude  wrote:
> Yes. That is what I was looking for.  Is there a simple way to (in this
> scenario)
>
>
>> out[[1]]
>
>    v1 v2
>  1  a  1
>  4  a  2
>  7  a  3
>
>> a <- out[[1]]
>
> for each one?
>
> Thanks!
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Newbie-Question-on-making-subsets-for-every-element-of-a-table-column-tp4581228p4581775.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Newbie Question on making subsets for every element of a table column

2012-04-23 Thread cyclondude
Yes. That is what I was looking for.  Is there a simple way to (in this
scenario)


> out[[1]]

v1 v2
  1  a  1
  4  a  2
  7  a  3 

> a <- out[[1]]

for each one?

Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/Newbie-Question-on-making-subsets-for-every-element-of-a-table-column-tp4581228p4581775.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Newbie Question on making subsets for every element of a table column

2012-04-23 Thread Petr Savicky
On Mon, Apr 23, 2012 at 10:58:26AM -0700, cyclondude wrote:
> Hello, very new to R, playing with tables, and I am trying to do 
> 
> x <- subset(data, columnlabel == x)
> 
> for every element in my column that I could find by using 
> 
> table (data [,"columnlabel"])

Hi.

The following may be close to what you require.

  #prepare some data
  dat <- expand.grid(v1=letters[1:3], v2=1:3)
  dat

v1 v2
  1  a  1
  2  b  1
  3  c  1
  4  a  2
  5  b  2
  6  c  2
  7  a  3
  8  b  3
  9  c  3

  out <- split(dat, dat$v1)

  #the first two groups are
  out[[1]]

v1 v2
  1  a  1
  4  a  2
  7  a  3

  out[[2]]

v1 v2
  2  b  1
  5  b  2
  8  b  3

Hope this helps.

Petr Savicky.

__
R-help@r-project.org 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.


[R] Newbie Question on making subsets for every element of a table column

2012-04-23 Thread cyclondude
Hello, very new to R, playing with tables, and I am trying to do 

x <- subset(data, columnlabel == x)

for every element in my column that I could find by using 

table (data [,"columnlabel"])

I'd appreciate any useful help and I'm sorry if I didn't get the terminology
perfect.  Thanks. 


--
View this message in context: 
http://r.789695.n4.nabble.com/Newbie-Question-on-making-subsets-for-every-element-of-a-table-column-tp4581228p4581228.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.