na Questions
5
Solved
Just like the question says. Is there a faster way to do what is done below when the vector size is very large (> 10M entries) using base R?
The code below works, but when the vector size ...
Disreputable asked 25/10 at 13:16
5
Solved
I have a column in a dataset looking like this:
cluster_id
1
1
1
1
NA
1
NA
NA
2
NA
2
NA
3
NA
NA
3
cluster_id <- c("1","1","1","1","NA","1...
Hottempered asked 27/9 at 10:0
4
Solved
I create a dataframe df.
df <- data.frame (id = 1:10,
var1 = 10:19,
var2 = sample(c(1:2,NA), 10, replace=T),
var3 = sample(c(3:5, NA), 10, replace=T))
What I need is a new column var4, w...
5
Solved
I want to compare two vectors elementwise to check whether an element in a certain position in the first vector is different from the element in the same position in the second vector.
The point is...
7
Solved
I have a dataframe (or datatable, if that's easier) with incomplete rows:
Input
ID Var1 Var2 Var3
1 2 5 1
2 12 3
3 8
4 4
Code
d <- data.frame(
ID = 1:4,
Var1 = c(2, 12, 8, 4),
Var2 = c(5, 3,...
Surrogate asked 28/5 at 10:17
15
Solved
Regarding the bounty
Ben Bolker's paste2-solution produces a "" when the strings that are pasted contains NA's in the same position. Like this,
> paste2(c("a","b", "c", NA), c("A","B", NA, NA)...
4
I have a data frame with a bunch of categorical variables. Some of them contain NA's and I use the addNA function to convert them to an explicit factor level. My problem comes when I try to treat t...
Dehorn asked 25/6, 2013 at 15:58
5
Solved
I am attempting to work through Hadley Wickham's R for Data Science and have gotten tripped up on the following question: "How could you use arrange() to sort all missing values to the start? (Hint...
8
We have a data frame from a CSV file. The data frame DF has columns that contain observed values and a column (VaR2) that contains the date at which a measurement has been taken. If the date was no...
3
Solved
I am trying to create a new vector that is the sum of 35 other vectors. The problem is that there are lots of NA values, but for this particular use, I want to treat those as zeros. Adding the vect...
6
Solved
I have a dataframe with the lengths and widths of various arthropods from the guts of salamanders. Because some guts had thousands of certain prey items, I only measured a subset of each prey type....
4
Solved
I have a data frame where each row is a vector of values of varying lengths. I would like to create a vector of the last true value in each row.
Here is an example data frame:
df <- read.tabl...
2
Solved
I have a somewhat messy dataset to clean. Some operations introduce NAs by coercion, but the dataset contains many NAs even without that. How can I determine which rows or elements had NAs introduc...
Gunboat asked 12/8, 2019 at 21:41
5
Solved
I generally prefer to code R so that I don't get warnings, but I don't know how to avoid getting a warning when using as.numeric to convert a character vector.
For example:
x <- as.numeric(c("...
8
Solved
I have a data frame with two columns "a" and "b" with alternating missing values (NA)
a b
dog <NA>
mouse <NA>
<NA> cat
bird <NA>
I want to "merge" / combine them to a ne...
Fonz asked 8/1, 2015 at 22:2
3
Solved
I have a column of a pandas dataframe that I got from a database query with blank cells. The blank cells become "None" and I want to check if each of the rows is None:
In [325]: yes_records_sampl...
4
Solved
I have the same question like solved here, but I have to work with data.table.
What is the best data.table-way to filter out all rows, where specific / "relevant" columns are all NA, unim...
Prorogue asked 25/5, 2023 at 20:40
4
a=c(1,2,NA,4)
b=c(10,NA,30,40)
weighted.mean(a,b,na.rm = T)
The above code gives me NA as the answer, I think na.rm only ignores the NA values in vector a and not b. How can I ignore the NA in ...
7
Solved
I have a complete dataframe. I want to 20% of the values in the dataframe to be replaced by NAs to simulate random missing data.
A <- c(1:10)
B <- c(11:20)
C <- c(21:30)
df<- data.fra...
Cricoid asked 13/12, 2014 at 0:36
3
Solved
I have a dataframe with an NA row:
df = data.frame(c("classA", NA, "classB"), t(data.frame(rep("A", 5), rep(NA, 5), rep("B", 5))))
rownames(df) <- c(1,2,3)
colnames(df) <- c("class", past...
3
I'm using the openxlsx package to read and write Excel files.
I've noticed that when I export the table to Excel with
write.xlsx(MyData, file="MyFile.xlsx")
NAs appear as #NUM! when the file is o...
6
Solved
I have a question similar to this one, but my dataset is a bit bigger: 50 columns with 1 column as UID and other columns carrying either TRUE or NA, I want to change all the NA to FALSE, but I don'...
Extensile asked 2/9, 2011 at 3:59
5
Solved
I apologize if there is an answer out there already for this... I looked but could not find one.
I am trying to convert a matrix of factors into a matrix of numbers that corresponds to each of the...
5
Solved
I have a dataframe with some NA values:
dfa <- data.frame(a=c(1,NA,3,4,5,NA),b=c(1,5,NA,NA,8,9),c=c(7,NA,NA,NA,2,NA))
dfa
I would like to replace the NAs with values in the same position in a...
2
Solved
As we learn from this answer, there's a substantial performance increase when using anyNA() over any(is.na()) to detect whether a vector has at least one NA element. This makes sense, as the algori...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.