Displaying 20 results from an estimated 20000 matches similar to: "How "else" works"
2002 Sep 18
2
Use of Apply to Change Values in Dataframe
I have a question about how apply() works for changing data values. I am
using it to change NA values to zero, but the question applies to other
value changing operations as well. If I have a dataframe "Dat" with columns
"a", "b" and "c" and there are some NA values in every column:
If I do:
Dat$a[is.na(Dat$a)] <- 0
then all the NA values are changed
2002 May 24
3
Converting Character Strings into Object Names
Is there a function to convert character strings to object references. For
example, I want to name sets of objects based on scenarios and the types of
data being stored. So the scenarios might be something like c("a", "b",
"c"), the types of data might have names like c("pass.trp", "trk.trp",
"cmute.trp"), and I want to assign data to
2005 Apr 07
2
Zipping Rdata Files
Saving Rdata files in a zip archive form can in some cases save a
considerable amount of disk space. R has the zip.file.extract function to
extract files from zip archives, but appears not to have any corresponding
function to save in zipped form. (At least I have not been able to find
anything in the help files or through searching the mail archives.) The
system function can be used to call gzip
2004 Apr 21
1
Error with 1.9.0 - winMenuAdd not usable in .Rprofile
I had this problem too. The documentation for the winMenus says that these
functions are part of the utils package. R must be loading this library
after it sources in Rprofile. If you add library(utils) to the beginning of
your .First function, it should take care of the problem.
Brian Gregor, P.E.
Transportation Planning Analysis Unit
Oregon Department of Transportation
Brian.J.GREGOR at
2005 Jul 12
1
question for IF ELSE usage
Hi R users,
Maybe the question is too simple.
In a IF ... ELSE ... statement "if(cond) cons.expr else alt.expr", IF and
ELSE should be at the same line?
For example,
if (x1==12)
{
y1 <- 5
}else
{
y1 <- 3
}
is right, while
if (x1==12)
{
y1 <- 5
}
else # Error: syntax error
{
y1 <- 3
}
is wrong?
Thanks
--
Xiaohua Dai
2004 Apr 08
1
Why are Split and Tapply so slow with named vectors, why is a for loop faster than mapply
First, here's the problem I'm working on so you understand the context. I
have a data frame of travel activity characteristics with 70,000+ records.
These activities are identified by unique chain numbers. (Activities are
part of trip chains.) There are 17,500 chains.
I use the chain numbers as factors to split various data fields into lists
of chain characteristics with each element of
2008 Apr 29
5
If(cond) statement
Why will this simple statement not work? I think I am following the
documentation for if(cond) statements, and I have tried wrapping the
cons.expr and alt.expr in {}, I get the same error. There is no example
in the help file, and this is not covered in the Introduction to R,
SimpleR or other tutorials I have looked into.
mxx=max(cpx_list$nMV);
mxy=max(trend_list$nMV);
if (mxx>mxy)
mxy=mxx
2019 Aug 16
1
Documenting else's greed
I was initially pretty shocked by the result in this question:
https://stackoverflow.com/questions/57527434/when-do-i-need-parentheses-around-an-if-statement-to-control-the-sequence-of-a-f
Briefly, the following returns 0, not 3 as might be expected:
if (TRUE) {
0
} else {
2
} + 3
At first I thought it the question was simply one of syntax
precedence, but I believe the result is too
2017 Jul 04
0
about adding a column for water year
Well, let's see:
1) You do not appear to understand basic flow control statements in R.
Note that (from ?if):
if(cond) expr
if(cond) cons.expr else alt.expr
where
"cond A length-one logical vector that is not NA."
Your cond is a vector of length nrow(DF), so you don't want if, you
want ifelse().
Did you fail to show us your warning messages??
2. Revising your code and
2002 Mar 12
1
RArcInfo Package, get.bnddata()
I am having trouble using get.bnddata() in the RArcInfo package. I
installed the version 0.2 binary of the package for Windows and am using R
1.4.1 on Windows NT 4.0. I have had no problems importing and plotting arc
data with get.arcdata() and plotarc(). plotpal() also works fine. I've
been able to use get.arcdata(), get.labdata(), get.paldata(),
get.tablenames(), get.tablefields(),
2017 Jul 04
5
about adding a column for water year
Hi R users,
I have a question about adding a column for water year. The dataframe has
the structure below. But the wyear column just shows one year. Could anyone
help me with this problem? Thanks.
DF
year month day time flow
1972 1 1 1972-01-01 5
1972 1 2 1972-01-02 5.5
1972 1 3 1972-01-03 6
...
1985 12
2003 Jul 23
2
paste and NAs
I understand how R treats NAs but in the situation below it would be nice to
have a na.skip argument to paste so it does not convert the NAs to "NA"s and
simply skips those elements of the vector for pasting.
> x
[1] "2.13" "2.3" NA NA "2.83" NA
> paste(x, "0", sep="")
[1] "2.130" "2.30"
2008 Mar 05
3
ipf function in R
Hi
I have a 3 x 2 contingency table:
10 20
30 40
50 60
I want to update the frequencies to new marginal totals:
100 130
40 80 110
I want to use the ipf (iterative proportional fitting) function which
is apparently in the cat package.
Can somebody please advice me how to input this data and invoke ipf in R
to obtain an updated contingency table?
Thanks.
By the way I am quite new to R.
--
Dr
2004 Apr 06
4
how to learn R quickly?
i am new to R,so i post here to ask you how to learn R quickly?
is there some usefull materials about using R.
ps:though the manual is a good materials,but it is not the best for a newbie,i think.
thank you !
2011 Mar 24
3
Extract the names of the arguments in an "expression"
Hi everybody:
I need to get the names of the arguments in an object of class "expression".
I've got the following expression:
> x <- expression(rho * cos(omega))
Is there any function or procedure that returns the names of the arguments
(in the example: "rho" and "omega")?
I tried a rough approach implemented in the function expr.args() shown
below. As
2011 Jul 27
0
[LLVMdev] Proposal for better assertions in LLVM
sorry, my previous message got sent too early
I think the macro should look something like this:
#define ASSERT_STRM(cond,expr) \
do {
if (cond) {
std::cerr << expr << std::end;
assertion_trap ();
}
} while (false)
On Tue, Jul 26, 2011 at 7:57 PM, Nathan Jeffords <blunted2night at gmail.com>wrote:
> wrapping the macro's body in:
>
> do { ... } while
2018 Nov 22
2
[tryExcept] New try Function
Hi everyone,
When dealing with errors, sometimes I want to run a bunch of code when an error occurs.
For now I usually use a structure such as:
res <- tryCatch(expr, error = function(cond) cond) # or try(expr)
if (inherits(res, ?error?)) # or inherits(res, ?try-error?)
# a bunch of code
I though it would be useful to have a function that does this naturally, so I came up with the attached
2018 Nov 23
1
[tryExcept] New try Function
Hi Emil,
First, thanks for the response. As you mentioned, a lot of times tryCatch
does the work, as you can return a value. However, sometimes it is useful
to assign several variables when an error occurs. You could do it with <<-,
but I prefer to reduce it's usage unless completely necessary.
I guess that the attachment was missed in the moderation. Here it is the
function:
2012 Jul 30
3
If/then statement, if in a list then
I need to write an if/then statement saying something along the lines of:
if (VALUE is in list) {...
How do I write that in R's language.
Thanks!
--
View this message in context: http://r.789695.n4.nabble.com/If-then-statement-if-in-a-list-then-tp4638346.html
Sent from the R help mailing list archive at Nabble.com.
2004 Aug 05
1
R interface to Python (in Windows)
I put a copy of R 1.8.1 for Windows on our FTP site at:
ftp://ftp.odot.state.or.us/outgoing/Test/. It should be there for a few
days before it gets deleted.
Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301 Ph: 503-986-4104
-----Original Message-----
From: Peter Wilkinson [mailto:pwilkinson at videotron.ca]