Re: [R] simple data.frame question

2012-05-16 Thread arun
Hi Troels,
Not sure this is what you want.


> X<-runif(9,0,10)
> FF1<-data.frame(ID=c(1,2,3)[rep(c(1,1,1,2,2,2,3,3,3))], 
> PERIOD=c(1,2,3)[rep(c(1,2,3),times=3)],X=X)
> FF1$X[4]<-NA
> FF1
  ID PERIOD  X
1  1  1 8.27119347
2  1  2 9.64698097
3  1  3 2.74132386
4  2  1 NA
5  2  2 4.29322683
6  2  3 5.09269667
7  3  1 4.07936332
8  3  2 7.41808455
9  3  3 0.01558664


A.K.





- Original Message -
From: Troels Ring 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, May 16, 2012 11:56 AM
Subject: [R] simple data.frame question

Dear friends - I hope you will forgive me another simple question, illustrated 
by

ID <- c(1,1,1,2,2,3,3,3)
PERIOD <- c(1,2,3,2,3,1,2,3)
X <- runif(8,0,10))

FF <- data.frame(ID=ID,PERIOD=PERIOD,X=X)

I need to the fourth value of X as NA, and ID and PERIOD is updated to 
1,1,1,2,2,2,3,3,3 and 1,2,3,1,2,3,1,2,3 respectively.
How do I use the pattern in ID and PERIOD to find the lacking X and put NA?

Best wishes

Troels Ring,
Aalborg, Denmark

__
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] simple data.frame question

2012-05-16 Thread Troels Ring

Thanks a lot - beautiful
Troels

Den 16-05-2012 19:29, David Winsemius skrev:


On May 16, 2012, at 11:56 AM, Troels Ring wrote:

Dear friends - I hope you will forgive me another simple question, 
illustrated by


ID <- c(1,1,1,2,2,3,3,3)
PERIOD <- c(1,2,3,2,3,1,2,3)
X <- runif(8,0,10))


Extraneous paren removed:



FF <- data.frame(ID=ID,PERIOD=PERIOD,X=X)

I need to the fourth value of X as NA, and ID and PERIOD is updated 
to 1,1,1,2,2,2,3,3,3 and 1,2,3,1,2,3,1,2,3 respectively.
How do I use the pattern in ID and PERIOD to find the lacking X and 
put NA?


> ffnew=merge(x=expand.grid(1:3,1:3),
+ y=FF, by =1:2, all.x=TRUE)
> ffnew
  Var1 Var2 X
111 6.6294571
212 0.5749111
313 8.7895630
421NA
522 5.7213062
623 6.1030507
731 8.9182841
832 4.2823937
933 8.8249263


Best wishes

Troels Ring,
Aalborg, Denmark

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


David Winsemius, MD
West Hartford, CT




__
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] simple data.frame question

2012-05-16 Thread David Winsemius


On May 16, 2012, at 11:56 AM, Troels Ring wrote:

Dear friends - I hope you will forgive me another simple question,  
illustrated by


ID <- c(1,1,1,2,2,3,3,3)
PERIOD <- c(1,2,3,2,3,1,2,3)
X <- runif(8,0,10))


Extraneous paren removed:



FF <- data.frame(ID=ID,PERIOD=PERIOD,X=X)

I need to the fourth value of X as NA, and ID and PERIOD is updated  
to 1,1,1,2,2,2,3,3,3 and 1,2,3,1,2,3,1,2,3 respectively.
How do I use the pattern in ID and PERIOD to find the lacking X and  
put NA?


> ffnew=merge(x=expand.grid(1:3,1:3),
+ y=FF, by =1:2, all.x=TRUE)
> ffnew
  Var1 Var2 X
111 6.6294571
212 0.5749111
313 8.7895630
421NA
522 5.7213062
623 6.1030507
731 8.9182841
832 4.2823937
933 8.8249263


Best wishes

Troels Ring,
Aalborg, Denmark

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


David Winsemius, MD
West Hartford, CT

__
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] simple data.frame question

2012-05-16 Thread Troels Ring
Dear friends - I hope you will forgive me another simple question, 
illustrated by


ID <- c(1,1,1,2,2,3,3,3)
PERIOD <- c(1,2,3,2,3,1,2,3)
X <- runif(8,0,10))

FF <- data.frame(ID=ID,PERIOD=PERIOD,X=X)

I need to the fourth value of X as NA, and ID and PERIOD is updated to 
1,1,1,2,2,2,3,3,3 and 1,2,3,1,2,3,1,2,3 respectively.

How do I use the pattern in ID and PERIOD to find the lacking X and put NA?

Best wishes

Troels Ring,
Aalborg, Denmark

__
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] simple data.frame question

2007-10-23 Thread jim holtman
Your first statement may create a data frame, but your second
statement now store a vector in an object with the same name, but is
now not a data frame, that is why it "appears" that the first row is
overwritten.  What are you trying to do?

On 10/23/07, pharos <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> At first I have to admit that I'm quite new to R and need some basic
> information. Although I searched the internet and this forum where I found
> answers to really sophisticated questions, I couldn't find the answer to my
> really simple one - or I didn't understand it for English is not my
> mothertongue.
> I'm using Rpad to simulate a webserver on my PC. Further I've got an html
>  with some checkboxes/radiobuttons. My first code-chunk attempts to
> create a data.frame (but I don't know, if I've done it correct):
>
>[i]statistik <- data.frame(car = factor(), ubahn = factor () [...],
> quantity = numeric())[/i]
>
> When clicking on a button, I want to submit the values from the  to
> the data.frame.
>
>[i]statistik <- c(car, autobus, ubahn, strassenbahn, bicycle, walk,
> quantity)[/i]
>
> When clicking another buttons I want to show the saved values.
>
>[i]print(statistik)[/i]
>
> What in fact happens is that by submiting the values, the first row of the
> data.frame is overwritten. At least that's what it looks like to me. If you
> need any further information, please let me know.
> I'd allready be happy if you could point out what's the exact place to look
> for in some kind of manual. Thanks for your help!
>
> --
> View this message in context: 
> http://www.nabble.com/simple-data.frame-question-tf4679785.html#a13371775
> 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
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] simple data.frame question

2007-10-23 Thread pharos

Hi,

At first I have to admit that I'm quite new to R and need some basic
information. Although I searched the internet and this forum where I found
answers to really sophisticated questions, I couldn't find the answer to my
really simple one - or I didn't understand it for English is not my
mothertongue. 
I'm using Rpad to simulate a webserver on my PC. Further I've got an html
 with some checkboxes/radiobuttons. My first code-chunk attempts to
create a data.frame (but I don't know, if I've done it correct):

[i]statistik <- data.frame(car = factor(), ubahn = factor () [...],
quantity = numeric())[/i]

When clicking on a button, I want to submit the values from the  to
the data.frame. 

[i]statistik <- c(car, autobus, ubahn, strassenbahn, bicycle, walk,
quantity)[/i]

When clicking another buttons I want to show the saved values.

[i]print(statistik)[/i]

What in fact happens is that by submiting the values, the first row of the
data.frame is overwritten. At least that's what it looks like to me. If you
need any further information, please let me know.
I'd allready be happy if you could point out what's the exact place to look
for in some kind of manual. Thanks for your help! 

-- 
View this message in context: 
http://www.nabble.com/simple-data.frame-question-tf4679785.html#a13371775
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.