Displaying 20 results from an estimated 8000 matches similar to: "NA-values and logical operation"
2013 Sep 04
4
Comments requested on "changedFiles" function
In a number of places internal to R, we need to know which files have
changed (e.g. after building a vignette). I've just written a general
purpose function "changedFiles" that I'll probably commit to R-devel.
Comments on the design (or bug reports) would be appreciated.
The source for the function and the Rd page for it are inline below.
----- changedFiles.R:
changedFiles
2002 Jun 09
1
Logical operators
Hello,
I have a csv-file which looks like:
#### pwt6_r.csv ####
code;year;rgdpch
AGO;1998;1234
ALB;1998;3576
ARG;1998;#NA
SVN;1996;13439
SWE;1996;21492
AGO;1960;#NA
ALB;1960;2345
ARG;1960;4634
#### pwt6_r.csv ####
To import this file i call:
pwt6<-read.csv("d:/pwt6_r.csv",header=T,na.strings="#NA",sep=";")
Now I want to generate a new data.frame which include
2010 Jun 21
1
replace NA-values
Dear list,
I'm trying to replace NA-values with the preceding values in that column.
This code works, but I am sure there is a more elegant way...
df <- data.frame(id = c("A1", NA, NA, NA, "B1",
NA, NA, "C1", NA, NA, NA, NA),
value = c(1:12))
rn <- c(rownames(df[!is.na(df$id),]), nrow(df)+1)
rn <-
2017 Jun 07
3
Problem related to rowSums
Hi...
I have a dataframe with n columns and n rows. I need to find how many rows
contains zero raw read count across all column.
Thanks
--
*Yogesh Gupta*
*Postdoctoral Researcher*
*Department of Biological Science*
*Seoul National University*
*Seoul, South Korea*
[[alternative HTML version deleted]]
2018 Mar 21
5
Sum of columns of a data frame equal to NA when all the elements are NA
Dear list users,
let me ask you this trivial question. I worked on that for a long time, by now.
Suppose to have a data frame with NAs and to sum some columns with rowSums:
df <- data.frame(A = runif(10), B = runif(10), C = rnorm(10))
df[1, ] <- NA
rowSums(df[ , which(names(df) %in% c("A","B"))], na.rm=T)
If all the elements of the selected columns are NA, rowSums
2017 Apr 01
3
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
In R 3.3.3, I observe the following on Ubuntu 16.04 (when building
from source as well as for the sudo apt r-base build):
> x <- c(NA, NaN)
> mean(x)
[1] NA
> mean(rev(x))
[1] NaN
> rowMeans(matrix(x, nrow = 1, ncol = 2))
[1] NA
> rowMeans(matrix(rev(x), nrow = 1, ncol = 2))
[1] NaN
> .rowMeans(x, m = 1, n = 2)
[1] NA
> .rowMeans(rev(x), m = 1, n = 2)
[1] NaN
>
2018 Mar 21
3
Sum of columns of a data frame equal to NA when all the elements are NA
What do you mean by "should not"?
NULL means "missing object" in R. The result of the sum function is always expected to be numeric... so NA_real or NA_integer could make sense as possible return values. But you cannot compute on NULL so no, that doesn't work.
See the note under the "Value" section of ?sum as to why zero is returned when all inputs are removed.
2018 Mar 21
0
Sum of columns of a data frame equal to NA when all the elements are NA
Should not the result be NULL if you have removed the NA with na.rm=TRUE ?
B.
> On Mar 21, 2018, at 11:44 AM, Stefano Sofia <stefano.sofia at regione.marche.it> wrote:
>
> Dear list users,
> let me ask you this trivial question. I worked on that for a long time, by now.
> Suppose to have a data frame with NAs and to sum some columns with rowSums:
>
> df <-
2018 Jan 30
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Hi Martin, Henrik,
Thanks for the follow up.
@Martin: I vote for 2) without *any* hesitation :-)
(and uniformity could be restored at some point in the
future by having prod(), rowSums(), colSums(), and others
align with the behavior of length() and sum())
Cheers,
H.
On 01/27/2018 03:06 AM, Martin Maechler wrote:
>>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
2009 Nov 03
2
Re place only first NA in column
Dear All,
I am trying to fill in a blank vector ("a") with one value at a time, with
the value of the number of rows in a randomized dataset with rowSums=0.
Below is the code I've got so far, but what I want to be as the last line is
" a[1st NA,]=nz"
such that this will run until all of my NAs are replaced with an integer
value based on randomizations.
2009 Jun 08
4
seq(...) strange logical value
Do you heve any idea why I get after this instruction everywhere false?
> seq (0, 1, by=0.1) == 0.3
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
But after different step it's ok:
> seq(0, 1, by=0.1) == 0.4
[1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
--
View this message in context:
2018 Mar 21
0
Sum of columns of a data frame equal to NA when all the elements are NA
On 21/03/2018 11:44 AM, Stefano Sofia wrote:
> Dear list users,
> let me ask you this trivial question. I worked on that for a long time, by now.
> Suppose to have a data frame with NAs and to sum some columns with rowSums:
>
> df <- data.frame(A = runif(10), B = runif(10), C = rnorm(10))
> df[1, ] <- NA
> rowSums(df[ , which(names(df) %in%
2018 Mar 21
2
Sum of columns of a data frame equal to NA when all the elements are NA
No. The empty sum is zero. Adding it to another sum should not change it. Nothing audacious about that. This is consistent; other definitions just cause trouble.
-pd
> On 21 Mar 2018, at 18:05 , Boris Steipe <boris.steipe at utoronto.ca> wrote:
>
> Surely the result of summation of non-existent values is not defined, is it not? And since the NA values have been _removed_,
2018 Mar 21
0
Sum of columns of a data frame equal to NA when all the elements are NA
Surely the result of summation of non-existent values is not defined, is it not? And since the NA values have been _removed_, there's nothing left to sum over. In fact, pretending the the result in that case is zero would appear audacious, no?
Cheers,
Boris
> On Mar 21, 2018, at 12:58 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
>
> What do you mean by
2012 Jan 10
4
Sum of a couple of variables of which a few have NA values
Dear everyone,
I have looked all over the internet but I cannot find a way to solve my problem.
In my data I want to sum a couple of variables. Some of these
variables have NA values, and when I add them together, the result is
NA
dat <- data.frame(
id = gl(5,1),
var1 = rnorm(5, 10),
var2 = rnorm(5, 7),
var3 = rnorm(5, 6),
var4 = rnorm(5, 3),
var5 = rnorm(5, 8)
)
dat[3,3] <- NA
dat[4,5]
2018 Mar 21
0
Sum of columns of a data frame equal to NA when all the elements are NA
I see: consistency with additive identity. That makes sense. Thanks.
B.
> On Mar 21, 2018, at 1:22 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> No. The empty sum is zero. Adding it to another sum should not change it. Nothing audacious about that. This is consistent; other definitions just cause trouble.
>
> -pd
>
>> On 21 Mar 2018, at 18:05 , Boris
2017 Apr 01
1
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
On Fri, Mar 31, 2017 at 10:14 PM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
> From ?NA
>
> Numerical computations using ?NA? will normally result in ?NA?: a
> possible exception is where ?NaN? is also involved, in which case
> either might result.
>
> and ?NaN
>
> Computations involving ?NaN? will return ?NaN? or perhaps ?NA?:
>
2008 Feb 15
2
Remove rows with NA across all columns
Hi
I have a data frame df with 3 columns. Some rows are NA across all 3 columns. How can I remove rows with NA across all columns?
df=data.frame(col1=c(1:3,NA,NA,4),col2=c(7:9,NA,NA,NA),col3=c(2:4,NA,NA,4))
Thanks
Joseph
____________________________________________________________________________________
Be a better friend, newshound, and
[[alternative HTML version deleted]]
2018 Mar 21
1
Sum of columns of a data frame equal to NA when all the elements are NA
"I see: consistency with additive identity. "
Ummm, well:
> 1+NULL
numeric(0)
> sum(1,NULL)
[1] 1
Of course, there could well be something here I don't get, but that doesn't
look very consistent to me. However, as I said privately, so long as the
corner case behavior is documented, which it is, I don't care.
Cheers,
Bert
Bert Gunter
"The trouble with
2009 Dec 19
3
integer(0) and NA do not equal FALSE
Hi,
A noobie question: I'm simply trying to run a conditional statement that
evaluates if a substring is found within a larger string. I find that if it
IS found, my function returns TRUE (great!), but if not, the condition does
not evaluate to FALSE.
ex):
if( grep("hi", "hop", fixed = TRUE) )
print('yes, your substring is in your string')
else