stevensanderson, to random
@stevensanderson@mstdn.social avatar

🚀 Elevate Your R Programming Skills: Removing Elements from Vectors

Want to level up your R programming game? Let's talk about removing specific elements from vectors! It's a fundamental skill.

But here's the real fun: try it yourself! Experiment with your own data and see which method resonates with you. To get yourself familiar with what's happening, you have to experiment.

#R

Post: https://www.spsanderson.com/steveondata/posts/2024-05-20/

stevensanderson, to programming
@stevensanderson@mstdn.social avatar

🔎 Selecting Columns Containing a Specific String in R: A Quick Guide 🚀

Hey R users! Need to select columns by a specific string? Here's how in base R, stringr, stringi, dplyr, and with a bonus from data.table.

🆒 R
✅ grepl
📦 stringr
📦 stringi
📦 dplyr

Bonus: 📦 data.table
library(data.table)
df_price <- df[, names(df) %like% "price"]

Happy coding! 🚀

Post: https://www.spsanderson.com/steveondata/posts/2024-05-15/

#R

image/png
image/png
image/png

stevensanderson, to programming
@stevensanderson@mstdn.social avatar

Want to check duplicate values across columns of a data.frame? Well you can do that in a basic way with TidyDensity and the check_duplicate_rows() function, or you can go through todays blog post for some other ideas with and

#R

Post: https://www.spsanderson.com/steveondata/posts/2024-05-14/

image/png

stevensanderson, to programming
@stevensanderson@mstdn.social avatar

Counting NA's across columns in #R sure you can do that!!

My post today uses and to accomplish this

#R

Post: https://www.spsanderson.com/steveondata/posts/2024-05-07/

image/png
image/png
image/png

stevensanderson, to programming
@stevensanderson@mstdn.social avatar
stevensanderson, to programming
@stevensanderson@mstdn.social avatar

🔍 How to Extract Last Row in Data Frame in R

Base R
Use nrow(my_df) to get the total rows.
Extract the last row with indexing: my_df[nrow(my_df), ].

dplyr
Use tail(my_df, 1) to get the last row.

data.table
Convert to data.table: my_dt <- as.data.table(my_df).
Get last row using .N: my_dt[.N].

Now you know three ways to extract the last row. Try it yourself! 📊

#RProgramming #DataFrames #CodingTips #R #RStats #Programming #Coding #Data #datatable #dplyr #baseR

Post: https://www.spsanderson.com/steveondata/posts/2024-04-18/

stevensanderson, to datascience
@stevensanderson@mstdn.social avatar

Learn how to set a data frame column as the index for faster data access and streamlined operations.

In R, utilize the setDT() function from or column_to_rownames() from to seamlessly set your desired column as the index. Try it out with your datasets and experience the boost in productivity!

#R 🚀📊

Post: https://www.spsanderson.com/steveondata/posts/2024-02-29/

stevensanderson, to random
@stevensanderson@mstdn.social avatar

Data analysis often involves reshaping messy datasets. Fear not, R's data.table package has your back with the awesome melt() function!

Here's the magic:

  • data.table object: Your data you want to reshape.
  • id.vars: Columns that stay put (like city names).
  • measure.vars: Columns you want to "melt" (like temperature values).

Post: https://www.spsanderson.com/steveondata/posts/2024-02-27/

#R

stevensanderson, to programming
@stevensanderson@mstdn.social avatar

The dcast function from R's data.table package provides a fast way to reshape data from long to wide format. It aggregates values like a pivot table in just one line. For example, to aggregate mtcars hp by cyl:

dcast(as.data.table(mtcars), cyl ~ ., value.var="hp", fun.aggregate=mean)

Post: https://www.spsanderson.com/steveondata/posts/2024-02-26/

#R

stevensanderson, to datascience
@stevensanderson@mstdn.social avatar

Taming Your Data with Filtering in R

Feeling lost in your data jungle? Filtering is your machete!

Master data.tables:

  • Filter by conditions
  • Combine conditions
  • Filter by list values

Conquer data.frames:

  • Use logical operators
  • Subset with row indices

#R

Post: https://www.spsanderson.com/steveondata/posts/2024-02-23/

devSJR, to random
@devSJR@fosstodon.org avatar

The practical thing about is that you can enter commands for each session that are always executed. For example, you can use this to load certain packages as standard. Here in the example I use the great library data.table, which is automatically loaded at each start of RKWard.

stevensanderson, to random
@stevensanderson@mstdn.social avatar

My TidyDensity package just got a major upgrade, powered by the blazing-fast data.table.

⚡️ And the best part? You get the speed boost no matter what format you choose.

Ready to experience the difference?

1.install.packages("TidyDensity")
2. Pick your output format: .return_tibble = TRUE for tibbles, .return_tibble = FALSE for data.tables.
3. Dive into your data

#R

Post: https://www.spsanderson.com/steveondata/posts/2024-01-12/

image/png

thadryanjs, to datascience

(1/n) Heads up/PSA/reminder for stats folks.

Almost misinformed my PI about a key variable the other day after stumbling into this little bit of computational profanity:

#rstats #data #datascience #research #stats

@academicsunite

thadryanjs,

(3/n) @academicsunite #rstats #data #datascience #research #stats

It's worth noting that both #dplyr and #datatable will save you from this. I prefer the #tidyverse.

image/png

stevensanderson, to random
@stevensanderson@mstdn.social avatar

Imagine you have a bunch of data points and you want to know how many belong to different categories. This is where grouped counting comes in. We've got three fantastic methods for you to explore, each with its own flair: aggregate(), dplyr, and data.table.

Happy counting, fellow data explorer! 🎉🔍 #DataAnalysis #RProgramming #ExploreData #dplyr #aggregate #baser #r #rstats #datatable

Post: https://www.spsanderson.com/steveondata/posts/2023-08-10/

image/png
image/png

stevensanderson, to opensource
@stevensanderson@mstdn.social avatar
devSJR, to bioinformatics
@devSJR@fosstodon.org avatar

Occasionally, I think about how to work effectively with . Currently, I am teaching my courses with again. I try to do most of it with packages from the base installation. is an exception. But otherwise, I like to use (very fast) instead of .
But there are more approaches, which are often simpler/faster/stable:

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • thenastyranch
  • magazineikmin
  • ethstaker
  • khanakhh
  • rosin
  • Youngstown
  • everett
  • slotface
  • ngwrru68w68
  • mdbf
  • GTA5RPClips
  • kavyap
  • DreamBathrooms
  • provamag3
  • cisconetworking
  • cubers
  • Leos
  • InstantRegret
  • Durango
  • tacticalgear
  • tester
  • osvaldo12
  • normalnudes
  • anitta
  • modclub
  • megavids
  • lostlight
  • All magazines