Hi,
How do I tell an if statement to generate two seperate outputs.
E.g If X>5 I want to create df1 and df2:
if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)}
Thanks,
James
--
View this message in context:
http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22650844.html
Sent from the R help mailing list archive at Nabble.com.
jimdare wrote:> Hi, > > How do I tell an if statement to generate two seperate outputs. > > E.g If X>5 I want to create df1 and df2: > > if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)} >almost there: if (X>5) {df1<-c(4,5,6,7,8); df2<-c(9,10,11,12,13)} vQ
if (X>5) {
df1<-c(4,5,6,7,8)
df2<-c(9,10,11,12,13)
}
hth,
Daniel Moreira, MD
jimdare <jamesdare26@gmail.com>
Sent by: r-help-bounces@r-project.org
03/22/2009 05:27 PM
To
r-help@r-project.org
cc
Subject
[R] If statement generates two outputs
Hi,
How do I tell an if statement to generate two seperate outputs.
E.g If X>5 I want to create df1 and df2:
if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)}
Thanks,
James
--
View this message in context:
http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22650844.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.
[[alternative HTML version deleted]]
Thanks very much Wacek Kusnierczyk wrote:> > jimdare wrote: >> Hi, >> >> How do I tell an if statement to generate two seperate outputs. >> >> E.g If X>5 I want to create df1 and df2: >> >> if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)} >> > almost there: > > if (X>5) {df1<-c(4,5,6,7,8); df2<-c(9,10,11,12,13)} > > vQ > > ______________________________________________ > R-help at 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. > >-- View this message in context: http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22650960.html Sent from the R help mailing list archive at Nabble.com.
Hi,
I tried to create the following if / else statement but I keep getting the
error "Error: unexpected '}' in
"size="large",center="none")
}" (I have highlighted the } in bold where the error is occuring). I
can't
seem to find a reason for this, does anyone know how I can fix it?
Thanks,
James
if (nostocks<=3)
{data1<-test[,data1stocks];
tex1<-latex(data1, file=paste(i$Species[1], "1.tex",
sep=""),
rowname = NULL,
cgroup = c("Fishstock",
stocknames,"Total"),
n.cgroup = c(1, rep(2,(nostocks+1)),
colheads = c("Year", rep(c("Catch",
"TACC"),
nostocks+1)),
size="large",center="none")
}else)
{data1<-test[,1:9];data2<-test[,data2stocks];
tex1<-latex(data1, file=paste(i$Species[1], "1.tex",
sep=""),
rowname = NULL,
cgroup = c("Fishstock",
stocknames,"Total"),
n.cgroup = c(1, rep(2,4)),
colheads = c("Year", rep(c("Catch",
"TACC"),
nostocks+1)),
size="large",center="none");
tex2<-latex(data2, file=paste(i$Species[1], "2.tex",
sep=""),
rowname = NULL,
cgroup = c("Fishstock",
stocknames,"Total"),
n.cgroup = c(1, rep(2,((nostocks-4)+1)),
colheads = c("Year", rep(c("Catch",
"TACC"),
nostocks+1)),size="large",center="none")
}
jimdare wrote:>
> Hi,
>
> How do I tell an if statement to generate two seperate outputs.
>
> E.g If X>5 I want to create df1 and df2:
>
> if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)}
>
> Thanks,
> James
>
--
View this message in context:
http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22652363.html
Sent from the R help mailing list archive at Nabble.com.
>From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>>Date: Sun, 22 Mar 2009 22:58:49 +0100 >just for fun, you could do this with multiassignment, e.g., using the >(highly experimental and premature!) rvalues: > source('http://miscell.googlecode.com/svn/rvalues/rvalues.r') >if (TRUE) > c(df1, df2) := list(4:8, 9:13) > dput(df1) > # 4:8 > dput(df2) > # 9:13 ------- Now THAT's what I call an overloaded operator! ^_^ But seriously: can someone explain to me what's going on in the rvalues.r code? I tried a simple experiment, replacing ":=" with a "colec" in the code, and of course the line c(df1, df2) colec list(4:8, 9:13) just gives me a "syntax error" response. Clearly I need a pointer to some documentation about how the colon and equals sign get "special treatment somewhere inside R. thanks Carl