Re: [R] using a variable in a subset of a dataframe

2008-04-01 Thread Henrique Dallazuanna
You can try this:

x - data.frame()
for(i in LETTERS[1:5]) x[1:10, i] - rnorm(10)
x


On 01/04/2008, Georg Ehret [EMAIL PROTECTED] wrote:
 Dear R community,I am using a dataset and would like to define new
  variables using a R variable:

  e.g.

  for (i in 1:10){
dataset$i-something
  }

  But this is not the right way, I get only one variable in dataset...
  How can I change this?

  Thank you!
  Georg.
  
  Georg Ehret
  Johns Hopkins
  Baltimore, MD

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



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
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] using a variable in a subset of a dataframe

2008-04-01 Thread Georg Ehret
Dear R community,I am using a dataset and would like to define new
variables using a R variable:

e.g.

for (i in 1:10){
   dataset$i-something
}

But this is not the right way, I get only one variable in dataset...
How can I change this?

Thank you!
Georg.

Georg Ehret
Johns Hopkins
Baltimore, MD

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


Re: [R] using a variable in a subset of a dataframe

2008-04-01 Thread Zaihra T

i m not sure what u really want to do but if ur looking for some subsample
   of dataset then u might wanna try this (say in case u want to resample ur
   dataset by column id in ur dataset then do

   resample-sample(dataset$id,n,replace=F)

   dataset-dataset[resample, ]

   note here n is the size of subset u wanna sample from ur dataset

   hope this helps.

   cheers

   tasneem zaihra

   On Tue, 1 Apr 2008 14:23:10 -0400 Georg Ehret wrote:
Dear R community, I am using a dataset and would like to define new
variables using a R variable:
   
e.g.
   
for (i in 1:10){
dataset$i-something
}
   
But this is not the right way, I get only one variable in dataset...
How can I change this?
   
Thank you!
Georg.  
Georg Ehret
Johns Hopkins
Baltimore, MD
   
[[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.
__
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] using a variable in a subset of a dataframe

2008-04-01 Thread K. Elo
Henrique Dallazuanna wrote (1.4.2008):
 You can try this:

 x - data.frame()
 for(i in LETTERS[1:5]) x[1:10, i] - rnorm(10)
 x

Or this:

--- cut here ---
df-data.frame(0) [obsolet, if df already exists]
for (i in 1:10) { df-data.frame(cbind(df,0)); names(df)
[ncol(df)]-as.character(i) }
--- cut here ---

How 'df' changes:
Step 1:
 df
  X0
1  0

Step 2 (for-loop): 
 df
  X0 1 2 3 4 5 6 7 8 9 10
1  0 0 0 0 0 0 0 0 0 0  0

Is this what You are looking for?

Kind regards,
Kimmo

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