What do you want to save?
Add Code snippet
New code examples in category R
-
Legion123 2021-09-09 19:24:02
r change column based on condition
# If a condition is met in a specific column (column "b" is 0), # change the value in column "est". Here the value is replaced # by the value for "a" in that same row where b == 0. df$est[df$b == 0] <- df$a[df$b == 0] Add solution -
Vernus 2021-09-08 02:06:02
delete first three lines dataframe R
df = df[-1,] #Remove first line of a dataframe remove <- 1:n df = df[-remove,] #Remove the first n lines of a dataframe #Always check if your object is a dataframe with class(df) e.g: > class(df) [1] "data.frame" Add solution -
Jane Black 2021-09-07 08:49:02
R upvar variable to level above
# Using <<- as opposed to <- in a function space will search for a variable of the same name in the level above. Example: # This can help to return multiple variables out of a function # An obvious alternative would be to return a list of desired... Add solution -
Laughsloudly 2021-09-05 23:06:02
cbind vectors of different lengths r
> l <- lapply(c(3,2,1,2,3),seq) > lapply(c("t","l","b","r"), bind.pad, l=l, len=4) [[1]] [,1] [,2] [,3] [,4] [,5] [1,] NA NA NA NA NA [2,] 1 NA NA NA 1 [3,] 2 1 NA 1 ... Add solution