sum Function in R (3 Examples) | Remove NA & Adding Up Column Values

preview_player
Показать описание

R code of this video:

# Example 1 - Basic application
x <- c(10, 5, 8, 3, 5) # Create example vector

sum(x) # Sum of example vector

# Example 2 - Handle NA values
x_NA <- c(x, NA) # Create example vector with NA
x_NA # Print example vector

sum(x_NA) # Try to get sum of NA vector

# Example 3 - Sum of data frame column
data(iris) # Load iris data
head(iris) # Head of iris data

sum(iris$Sepal.Length) # Sum of first column of iris
Рекомендации по теме
Комментарии
Автор

Plz tell me how can we get derivative of. Function like : sum(log(a)+ b ) with respect to a or b

maleejahmed
Автор

Hello. If I wanted to sum variable "Sepal.Length", but only from values 2 to 7, how would I go about it? Essentially, just get the sum of a portion of the variable. Thank you.

hansestrada
Автор

how can i sum, mean, from species data, because the variable data is character?

ruciradivanismara
Автор

Hi! I have a question with Iris data. How can I write the R code the sum of the (petal width) value of iris flowers of the "iris-setosa" type?

elifozcan
Автор

How can I sum even numbers from 2 to 482?

marapaularamos-cabrera
Автор

Can you explain how to create a column and sum unique values from column A as example ? thank you.

sureshvinayaka