Re: [R] loop on list levels and names

2010-01-22 Thread Matthew Dowle
data.table is the package name too. Make sure you find ?"[.data.table" which 
is linked from ?data.table.
You could just do a mean of one variable first, and then build it up from 
there  e.g.  dataset[, mean(epLsar), by="SPECSHOR,BONE"].
To get multiple columns of output,  wrap with DT() like this   dataset[, 
DT(mean(epLsar),min(epLsar)), by="SPECSHOR,BONE"]
Btw, v1.3 on r-forge fixes a version check warning with v1.2 on R2.10+ (not 
fixed by me but thanks to a contributor) so if you can't live with the 
warning messages, you can install v1.3 from r-forge like this :
install.packages("data.table",repos="http://r-forge.r-project.org";)

Best of luck.

"Ivan Calandra"  wrote in message 
news:4b59d93c.5080...@uni-hamburg.de...
Thanks for your advice, I will work on it then!
Just one last question. In which package can I find the function
data.table?
Ivan

Le 1/22/2010 17:18, Matthew Dowle a écrit :
> Great.
>
> If you mean the crantastic r package, sorry I wasn't clear,  I meant the
> crantastic website http://crantastic.org/.
> If you meant the description of plyr then if the description looks useful
> then click the link taking you to the package documentation and read it.
> Same for any of the other packages.
>
> The idea,  I think,  is that its a good idea to make yourself aware of the
> most popular packages i.e. perhaps just read the descriptions of the top 
> 30
> or something like that maybe.  Maybe it helps you avoid re-inventing the
> wheel.  That seems to be the case here.
>
> Re Don's reply, sure you can use split().  But that will use more memory.
> And using paste for this?  Ok, it works, but don't you want to use better
> ways?  data.table should be much faster and more convenient, quicker to
> write than split and paste like that.
>
> HTH
>
>
> "Ivan Calandra"  wrote in message
> news:4b59bdc5.60...@uni-hamburg.de...
> I didn't know about crantastic actually.
> I've looked what it is exactly and it indeed looks interesting, but I
> don't really see how I would know that it would help me for the task.
> There's a description of what it was built for, but how can I then know
> which function from this package can help me?
>
> Thanks for your answer (you all), I'll work on it!
> I'll keep you informed if it doesn't work (!), and I'll go vote on
> crantastic when I'll have a bit more experience with the packages I use
> (right now I'm just using the ones I was told for one specific
> function), but don't worry I won't forget. As you said "It only works if
> users contribute to it". That makes the power of R!
>
> Ivan
>
>
>
> Le 1/21/2010 19:01, Matthew Dowle a écrit :
>
>> One way is :
>>
>> dataset = data.table(ssfamed)
>> dataset[,<   whatever "some functions" are on Asfc, Smc, epLsar, etc>,
>> by="SPECSHOR,BONE"]
>>
>> Your SPECSHOR and BONE names will be in your result alongside the results
>> of
>> the
>>
>> Or try package plyr which does this sort of thing too.  And sqldf may be
>> better if you know SQL and prefer it.  There are actually zillions of 
>> ways
>> to do it : by(), doBy() etc etc
>>
>> If you get your code working the way its constructed currently,  its 
>> going
>> to be very slow, because of those "==".   data.table doesn't do that and
>> is
>> pretty fast for this kind of thing. You might find that plyr is easier to
>> use and more flexible though if speed isn't an issue,  depending on
>> exactly
>> what you want to do.
>>
>> Whichever way you decide,  consider voting on crantastic for the package
>> you
>> end up using,  and that may be a quick and easy way for you to help new R
>> users in the future, and help us all by reducing the r-help traffic on 
>> the
>> same subject over and over again.
>>
>> Note that plyr is the 2nd spot on crantastic,  it would have solved your
>> problem without needing to write that code.  If you check crantastic 
>> first
>> and make sure you're aware of popular packages, it might avoid getting
>> stuck
>> in this way again.  It only works if users contribute to it though.
>>
>>
>> "Ivan Calandra"   wrote in message
>> news:4b587cdd.4070...@uni-hamburg.de...
>>
>>
>>> Hi everybody!
>>>
>>> To use some functions, I have to transform my dataset into a list, where
>>> each element contains one group, and I have to prepare a list for each
>>> variable I have (altogether I have 15 variables, and many entries per
>>> factor level)
>>>
>>> Here is some part of my dataset:
>>> SPECSHORBONEAsfcSmcepLsar
>>> cotautx454.39036929.2616380.001136
>>> cotautx117.4457114.2918840.00056
>>> cotautx381.02468215.3130170.002324
>>> cotautx159.08178918.1345330.000462
>>> cotautm160.6415036.4113320.000571
>>> cotautm79.2380233.8282540.001182
>>> cotautm143.2065511.9218990.000192
>>> cotautm115.47699633.1163860.000417
>>> cotautm594.25623472.5381310.000477
>>> eqgretx188.2613248.2790960.0007

Re: [R] loop on list levels and names

2010-01-22 Thread Ivan Calandra

Thanks for your advice, I will work on it then!
Just one last question. In which package can I find the function 
data.table?

Ivan

Le 1/22/2010 17:18, Matthew Dowle a écrit :

Great.

If you mean the crantastic r package, sorry I wasn't clear,  I meant the
crantastic website http://crantastic.org/.
If you meant the description of plyr then if the description looks useful
then click the link taking you to the package documentation and read it.
Same for any of the other packages.

The idea,  I think,  is that its a good idea to make yourself aware of the
most popular packages i.e. perhaps just read the descriptions of the top 30
or something like that maybe.  Maybe it helps you avoid re-inventing the
wheel.  That seems to be the case here.

Re Don's reply, sure you can use split().  But that will use more memory.
And using paste for this?  Ok, it works, but don't you want to use better
ways?  data.table should be much faster and more convenient, quicker to
write than split and paste like that.

HTH


"Ivan Calandra"  wrote in message
news:4b59bdc5.60...@uni-hamburg.de...
I didn't know about crantastic actually.
I've looked what it is exactly and it indeed looks interesting, but I
don't really see how I would know that it would help me for the task.
There's a description of what it was built for, but how can I then know
which function from this package can help me?

Thanks for your answer (you all), I'll work on it!
I'll keep you informed if it doesn't work (!), and I'll go vote on
crantastic when I'll have a bit more experience with the packages I use
(right now I'm just using the ones I was told for one specific
function), but don't worry I won't forget. As you said "It only works if
users contribute to it". That makes the power of R!

Ivan



Le 1/21/2010 19:01, Matthew Dowle a écrit :
   

One way is :

dataset = data.table(ssfamed)
dataset[,<   whatever "some functions" are on Asfc, Smc, epLsar, etc>,
by="SPECSHOR,BONE"]

Your SPECSHOR and BONE names will be in your result alongside the results
of
the

Or try package plyr which does this sort of thing too.  And sqldf may be
better if you know SQL and prefer it.  There are actually zillions of ways
to do it : by(), doBy() etc etc

If you get your code working the way its constructed currently,  its going
to be very slow, because of those "==".   data.table doesn't do that and
is
pretty fast for this kind of thing. You might find that plyr is easier to
use and more flexible though if speed isn't an issue,  depending on
exactly
what you want to do.

Whichever way you decide,  consider voting on crantastic for the package
you
end up using,  and that may be a quick and easy way for you to help new R
users in the future, and help us all by reducing the r-help traffic on the
same subject over and over again.

Note that plyr is the 2nd spot on crantastic,  it would have solved your
problem without needing to write that code.  If you check crantastic first
and make sure you're aware of popular packages, it might avoid getting
stuck
in this way again.  It only works if users contribute to it though.


"Ivan Calandra"   wrote in message
news:4b587cdd.4070...@uni-hamburg.de...

 

Hi everybody!

To use some functions, I have to transform my dataset into a list, where
each element contains one group, and I have to prepare a list for each
variable I have (altogether I have 15 variables, and many entries per
factor level)

Here is some part of my dataset:
SPECSHORBONEAsfcSmcepLsar
cotautx454.39036929.2616380.001136
cotautx117.4457114.2918840.00056
cotautx381.02468215.3130170.002324
cotautx159.08178918.1345330.000462
cotautm160.6415036.4113320.000571
cotautm79.2380233.8282540.001182
cotautm143.2065511.9218990.000192
cotautm115.47699633.1163860.000417
cotautm594.25623472.5381310.000477
eqgretx188.2613248.2790960.000777
eqgretx152.4442162.5963250.001022
eqgretx256.6015078.2790960.000566
eqgretx250.81644518.1345330.000535
eqgretx272.39671124.4928790.000585
eqgretm172.632644.2918840.001781
eqgretm189.44109714.4254980.001347
eqgretm170.74378813.5644720.000602
eqgretm158.96084910.3852990.001189
eqgretm80.9724083.8282540.000644
gicamtx294.4940019.6567380.000524
gicamtx267.12676519.1280240.000647
gicamtx81.8886584.7820060.000492
gicamtx168.3290812.7299390.001097
gicamtx123.2960567.0074270.000659
gicamtm94.26488718.1345330.000752
gicamtm54.3173953.8282540.00038
gicamtm55.97888317.1675340.000141
gicamtm279.59799315.3130170.000398
gicamtm288.26255618.1345330.001043

What I do next is:

list_Asfc<- l

Re: [R] loop on list levels and names

2010-01-22 Thread Matthew Dowle

Great.

If you mean the crantastic r package, sorry I wasn't clear,  I meant the 
crantastic website http://crantastic.org/.
If you meant the description of plyr then if the description looks useful 
then click the link taking you to the package documentation and read it. 
Same for any of the other packages.

The idea,  I think,  is that its a good idea to make yourself aware of the 
most popular packages i.e. perhaps just read the descriptions of the top 30 
or something like that maybe.  Maybe it helps you avoid re-inventing the 
wheel.  That seems to be the case here.

Re Don's reply, sure you can use split().  But that will use more memory. 
And using paste for this?  Ok, it works, but don't you want to use better 
ways?  data.table should be much faster and more convenient, quicker to 
write than split and paste like that.

HTH


"Ivan Calandra"  wrote in message 
news:4b59bdc5.60...@uni-hamburg.de...
I didn't know about crantastic actually.
I've looked what it is exactly and it indeed looks interesting, but I
don't really see how I would know that it would help me for the task.
There's a description of what it was built for, but how can I then know
which function from this package can help me?

Thanks for your answer (you all), I'll work on it!
I'll keep you informed if it doesn't work (!), and I'll go vote on
crantastic when I'll have a bit more experience with the packages I use
(right now I'm just using the ones I was told for one specific
function), but don't worry I won't forget. As you said "It only works if
users contribute to it". That makes the power of R!

Ivan



Le 1/21/2010 19:01, Matthew Dowle a écrit :
> One way is :
>
> dataset = data.table(ssfamed)
> dataset[,<  whatever "some functions" are on Asfc, Smc, epLsar, etc>,
> by="SPECSHOR,BONE"]
>
> Your SPECSHOR and BONE names will be in your result alongside the results 
> of
> the
>
> Or try package plyr which does this sort of thing too.  And sqldf may be
> better if you know SQL and prefer it.  There are actually zillions of ways
> to do it : by(), doBy() etc etc
>
> If you get your code working the way its constructed currently,  its going
> to be very slow, because of those "==".   data.table doesn't do that and 
> is
> pretty fast for this kind of thing. You might find that plyr is easier to
> use and more flexible though if speed isn't an issue,  depending on 
> exactly
> what you want to do.
>
> Whichever way you decide,  consider voting on crantastic for the package 
> you
> end up using,  and that may be a quick and easy way for you to help new R
> users in the future, and help us all by reducing the r-help traffic on the
> same subject over and over again.
>
> Note that plyr is the 2nd spot on crantastic,  it would have solved your
> problem without needing to write that code.  If you check crantastic first
> and make sure you're aware of popular packages, it might avoid getting 
> stuck
> in this way again.  It only works if users contribute to it though.
>
>
> "Ivan Calandra"  wrote in message
> news:4b587cdd.4070...@uni-hamburg.de...
>
>> Hi everybody!
>>
>> To use some functions, I have to transform my dataset into a list, where
>> each element contains one group, and I have to prepare a list for each
>> variable I have (altogether I have 15 variables, and many entries per
>> factor level)
>>
>> Here is some part of my dataset:
>> SPECSHORBONEAsfcSmcepLsar
>> cotautx454.39036929.2616380.001136
>> cotautx117.4457114.2918840.00056
>> cotautx381.02468215.3130170.002324
>> cotautx159.08178918.1345330.000462
>> cotautm160.6415036.4113320.000571
>> cotautm79.2380233.8282540.001182
>> cotautm143.2065511.9218990.000192
>> cotautm115.47699633.1163860.000417
>> cotautm594.25623472.5381310.000477
>> eqgretx188.2613248.2790960.000777
>> eqgretx152.4442162.5963250.001022
>> eqgretx256.6015078.2790960.000566
>> eqgretx250.81644518.1345330.000535
>> eqgretx272.39671124.4928790.000585
>> eqgretm172.632644.2918840.001781
>> eqgretm189.44109714.4254980.001347
>> eqgretm170.74378813.5644720.000602
>> eqgretm158.96084910.3852990.001189
>> eqgretm80.9724083.8282540.000644
>> gicamtx294.4940019.6567380.000524
>> gicamtx267.12676519.1280240.000647
>> gicamtx81.8886584.7820060.000492
>> gicamtx168.3290812.7299390.001097
>> gicamtx123.2960567.0074270.000659
>> gicamtm94.26488718.1345330.000752
>> gicamtm54.3173953.8282540.00038
>> gicamtm55.97888317.1675340.000141
>> gicamtm279.59799315.3130170.000398
>> gicamtm288.26255618.1345330.001043
>>
>> What I do next is:
>> 
>> 

Re: [R] loop on list levels and names

2010-01-22 Thread Don MacQueen
Without reading all the details of your question, it looks like maybe 
split() is what you want.


 split( dataset, paste(dataset$SPECSHOR,dataset$BONE) )

or

  split( dataset[,3], paste(dataset$SPECSHOR,dataset$BONE) )

-Don

At 5:12 PM +0100 1/21/10, Ivan Calandra wrote:

Hi everybody!

To use some functions, I have to transform my dataset into a list, where
each element contains one group, and I have to prepare a list for each
variable I have (altogether I have 15 variables, and many entries per
factor level)

Here is some part of my dataset:
SPECSHORBONEAsfcSmcepLsar
cotautx454.39036929.2616380.001136
cotautx117.4457114.2918840.00056
cotautx381.02468215.3130170.002324
cotautx159.08178918.1345330.000462
cotautm160.6415036.4113320.000571
cotautm79.2380233.8282540.001182
cotautm143.2065511.9218990.000192
cotautm115.47699633.1163860.000417
cotautm594.25623472.5381310.000477
eqgretx188.2613248.2790960.000777
eqgretx152.4442162.5963250.001022
eqgretx256.6015078.2790960.000566
eqgretx250.81644518.1345330.000535
eqgretx272.39671124.4928790.000585
eqgretm172.632644.2918840.001781
eqgretm189.44109714.4254980.001347
eqgretm170.74378813.5644720.000602
eqgretm158.96084910.3852990.001189
eqgretm80.9724083.8282540.000644
gicamtx294.4940019.6567380.000524
gicamtx267.12676519.1280240.000647
gicamtx81.8886584.7820060.000492
gicamtx168.3290812.7299390.001097
gicamtx123.2960567.0074270.000659
gicamtm94.26488718.1345330.000752
gicamtm54.3173953.8282540.00038
gicamtm55.97888317.1675340.000141
gicamtm279.59799315.3130170.000398
gicamtm288.26255618.1345330.001043

What I do next is:

list_Asfc <- list()
list_Asfc[[1]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tx', 3]
list_Asfc[[2]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tm', 3]


And so on for each level of SPECSHOR and BONE

I'm stuck on 2 parts:
- in a loop or something similar, I would like the 1st element of the
list to be filled by the values for the 1st variable with the first
level of my factors (i.e. cotau + tx), and then the 2nd element with the
2nd level (i.e. cotau + tm) and so on. As shown above, I know how to do
it if I enter manually the different levels, but I have no idea which
function I should use so that each combination of factor will be used.
See what I mean?

- I would then like to run it in a loop or something for each variable.
It is by itself not so complicated, but I don't know how to give the
correct name to my list. I want the list containing the data for Asfc to
be named "list_Asfc".
Here is what I tried:

seq.num <- c(seq(3,5,1)) #the indexes of the variables
for(i in 1:length(seq.num)) {
  k <- seq.num[i]
  name.num <- names(ssfamed)[k]
  list <- list()
  list[[1]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tx', i]
  list[[2]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tm', i]
  names(list) <- c("cotau_tx", "cotau_tm") #I have more and the 1st
question should help me on that too
}

After names(list) I need to insert something like: name_list <- list
But I don't know how to give it the correct name. How do we change the
name of an object? Or am I on the wrong path?

Thank you in advance for your help.
Ivan

PS: if necessary: under Windows XP, R2.10.












[[alternative HTML version deleted]]

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



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
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] loop on list levels and names

2010-01-22 Thread Ivan Calandra

I didn't know about crantastic actually.
I've looked what it is exactly and it indeed looks interesting, but I 
don't really see how I would know that it would help me for the task. 
There's a description of what it was built for, but how can I then know 
which function from this package can help me?


Thanks for your answer (you all), I'll work on it!
I'll keep you informed if it doesn't work (!), and I'll go vote on 
crantastic when I'll have a bit more experience with the packages I use 
(right now I'm just using the ones I was told for one specific 
function), but don't worry I won't forget. As you said "It only works if 
users contribute to it". That makes the power of R!


Ivan



Le 1/21/2010 19:01, Matthew Dowle a écrit :

One way is :

dataset = data.table(ssfamed)
dataset[,<  whatever "some functions" are on Asfc, Smc, epLsar, etc>,
by="SPECSHOR,BONE"]

Your SPECSHOR and BONE names will be in your result alongside the results of
the

Or try package plyr which does this sort of thing too.  And sqldf may be
better if you know SQL and prefer it.  There are actually zillions of ways
to do it : by(), doBy() etc etc

If you get your code working the way its constructed currently,  its going
to be very slow, because of those "==".   data.table doesn't do that and is
pretty fast for this kind of thing. You might find that plyr is easier to
use and more flexible though if speed isn't an issue,  depending on exactly
what you want to do.

Whichever way you decide,  consider voting on crantastic for the package you
end up using,  and that may be a quick and easy way for you to help new R
users in the future, and help us all by reducing the r-help traffic on the
same subject over and over again.

Note that plyr is the 2nd spot on crantastic,  it would have solved your
problem without needing to write that code.  If you check crantastic first
and make sure you're aware of popular packages, it might avoid getting stuck
in this way again.  It only works if users contribute to it though.


"Ivan Calandra"  wrote in message
news:4b587cdd.4070...@uni-hamburg.de...
   

Hi everybody!

To use some functions, I have to transform my dataset into a list, where
each element contains one group, and I have to prepare a list for each
variable I have (altogether I have 15 variables, and many entries per
factor level)

Here is some part of my dataset:
SPECSHORBONEAsfcSmcepLsar
cotautx454.39036929.2616380.001136
cotautx117.4457114.2918840.00056
cotautx381.02468215.3130170.002324
cotautx159.08178918.1345330.000462
cotautm160.6415036.4113320.000571
cotautm79.2380233.8282540.001182
cotautm143.2065511.9218990.000192
cotautm115.47699633.1163860.000417
cotautm594.25623472.5381310.000477
eqgretx188.2613248.2790960.000777
eqgretx152.4442162.5963250.001022
eqgretx256.6015078.2790960.000566
eqgretx250.81644518.1345330.000535
eqgretx272.39671124.4928790.000585
eqgretm172.632644.2918840.001781
eqgretm189.44109714.4254980.001347
eqgretm170.74378813.5644720.000602
eqgretm158.96084910.3852990.001189
eqgretm80.9724083.8282540.000644
gicamtx294.4940019.6567380.000524
gicamtx267.12676519.1280240.000647
gicamtx81.8886584.7820060.000492
gicamtx168.3290812.7299390.001097
gicamtx123.2960567.0074270.000659
gicamtm94.26488718.1345330.000752
gicamtm54.3173953.8282540.00038
gicamtm55.97888317.1675340.000141
gicamtm279.59799315.3130170.000398
gicamtm288.26255618.1345330.001043

What I do next is:

list_Asfc<- list()
list_Asfc[[1]]<- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tx', 3]
list_Asfc[[2]]<- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tm', 3]


And so on for each level of SPECSHOR and BONE

I'm stuck on 2 parts:
- in a loop or something similar, I would like the 1st element of the
list to be filled by the values for the 1st variable with the first
level of my factors (i.e. cotau + tx), and then the 2nd element with the
2nd level (i.e. cotau + tm) and so on. As shown above, I know how to do
it if I enter manually the different levels, but I have no idea which
function I should use so that each combination of factor will be used.
See what I mean?

- I would then like to run it in a loop or something for each variable.
It is by itself not so complicated, but I don't know how to give the
correct name to my list. I want the list containing the data for Asfc to
be named "list_Asfc".
Here is what I tried:

seq.num<- c(seq(3,5,1)) #the indexes of the variables
for(i in 1:length(seq.num)) {
  k<- seq.num[i]
  name.num<- names(ssfamed)[k]
  list<- list()
  

Re: [R] loop on list levels and names

2010-01-21 Thread Matthew Dowle
One way is :

dataset = data.table(ssfamed)
dataset[, < whatever "some functions" are on Asfc, Smc, epLsar, etc >, 
by="SPECSHOR,BONE"]

Your SPECSHOR and BONE names will be in your result alongside the results of 
the 

Or try package plyr which does this sort of thing too.  And sqldf may be 
better if you know SQL and prefer it.  There are actually zillions of ways 
to do it : by(), doBy() etc etc

If you get your code working the way its constructed currently,  its going 
to be very slow, because of those "==".   data.table doesn't do that and is 
pretty fast for this kind of thing. You might find that plyr is easier to 
use and more flexible though if speed isn't an issue,  depending on exactly 
what you want to do.

Whichever way you decide,  consider voting on crantastic for the package you 
end up using,  and that may be a quick and easy way for you to help new R 
users in the future, and help us all by reducing the r-help traffic on the 
same subject over and over again.

Note that plyr is the 2nd spot on crantastic,  it would have solved your 
problem without needing to write that code.  If you check crantastic first 
and make sure you're aware of popular packages, it might avoid getting stuck 
in this way again.  It only works if users contribute to it though.


"Ivan Calandra"  wrote in message 
news:4b587cdd.4070...@uni-hamburg.de...
> Hi everybody!
>
> To use some functions, I have to transform my dataset into a list, where
> each element contains one group, and I have to prepare a list for each
> variable I have (altogether I have 15 variables, and many entries per
> factor level)
>
> Here is some part of my dataset:
> SPECSHORBONEAsfcSmcepLsar
> cotautx454.39036929.2616380.001136
> cotautx117.4457114.2918840.00056
> cotautx381.02468215.3130170.002324
> cotautx159.08178918.1345330.000462
> cotautm160.6415036.4113320.000571
> cotautm79.2380233.8282540.001182
> cotautm143.2065511.9218990.000192
> cotautm115.47699633.1163860.000417
> cotautm594.25623472.5381310.000477
> eqgretx188.2613248.2790960.000777
> eqgretx152.4442162.5963250.001022
> eqgretx256.6015078.2790960.000566
> eqgretx250.81644518.1345330.000535
> eqgretx272.39671124.4928790.000585
> eqgretm172.632644.2918840.001781
> eqgretm189.44109714.4254980.001347
> eqgretm170.74378813.5644720.000602
> eqgretm158.96084910.3852990.001189
> eqgretm80.9724083.8282540.000644
> gicamtx294.4940019.6567380.000524
> gicamtx267.12676519.1280240.000647
> gicamtx81.8886584.7820060.000492
> gicamtx168.3290812.7299390.001097
> gicamtx123.2960567.0074270.000659
> gicamtm94.26488718.1345330.000752
> gicamtm54.3173953.8282540.00038
> gicamtm55.97888317.1675340.000141
> gicamtm279.59799315.3130170.000398
> gicamtm288.26255618.1345330.001043
>
> What I do next is:
> 
> list_Asfc <- list()
> list_Asfc[[1]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tx', 3]
> list_Asfc[[2]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tm', 3]
> 
>
> And so on for each level of SPECSHOR and BONE
>
> I'm stuck on 2 parts:
> - in a loop or something similar, I would like the 1st element of the
> list to be filled by the values for the 1st variable with the first
> level of my factors (i.e. cotau + tx), and then the 2nd element with the
> 2nd level (i.e. cotau + tm) and so on. As shown above, I know how to do
> it if I enter manually the different levels, but I have no idea which
> function I should use so that each combination of factor will be used.
> See what I mean?
>
> - I would then like to run it in a loop or something for each variable.
> It is by itself not so complicated, but I don't know how to give the
> correct name to my list. I want the list containing the data for Asfc to
> be named "list_Asfc".
> Here is what I tried:
> 
> seq.num <- c(seq(3,5,1)) #the indexes of the variables
> for(i in 1:length(seq.num)) {
>  k <- seq.num[i]
>  name.num <- names(ssfamed)[k]
>  list <- list()
>  list[[1]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tx', i]
>  list[[2]] <- ssfamed[ssfamed$SPECSHOR=='cotau'&ssfamed$BONE=='tm', i]
>  names(list) <- c("cotau_tx", "cotau_tm") #I have more and the 1st
> question should help me on that too
> }
> 
> After names(list) I need to insert something like: name_list <- list
> But I don't know how to give it the correct name. How do we change the
> name of an object? Or am I on the wrong path?
>
> Thank you in advance for your help.
> Ivan
>
> PS: if necessary: under Windows XP, R2.10.
>
>
>
>
>
>
>
>
>
>
>
>
> [[alternative HTML