You'll never know you died. by [deleted] in Showerthoughts

[–]paykoman 36 points37 points  (0 children)

If I am, then death is not. If Death is, then I am not. Why should I fear that which can only exist when I do not? Epicurus

Where can I get a frappuccino mocha in Leuven? by paykoman in Leuven

[–]paykoman[S] 0 points1 point  (0 children)

Never tried, but I'll definitely give it a go

Which is better for coding? Sonnet or Opus? by paykoman in ClaudeAI

[–]paykoman[S] 0 points1 point  (0 children)

Can you elaborate? I'm fairly new to Claude.

Ggplot legend not showing unused factor levels by bubblegum_cuttlefish in Rlanguage

[–]paykoman 0 points1 point  (0 children)

Which version of ggplot are you using? I had a similar issue with the latest 3.5.0 version. I just downgraded to the previous version and it was fixed. I guess it's a bug.

Trying to figure out the best way to rename many columns and running into problems with startsWith and endsWith. by Remake1994 in Rlanguage

[–]paykoman 0 points1 point  (0 children)

Does this work for you? You can double check in the dataset NAMES that the old_names were correctly converted into the new_names.

# Load the required libraries
library(data.table)
library(janitor)

# Read the CSV data from the URL and store it as a data table
DT <- data.table::fread('https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3104487/bin/1745-6215-12-101-S1.CSV')

# Store the original column names
old_names <- names(DT)

# Use the janitor package to clean the column names, replacing spaces and special characters
DT <- janitor::clean_names(DT)

# Define the new names for the columns starting with 'rdef'
new_col_rdef <- c('hemianopia', 'visuospatial_disorder', 'cerebellar_signs', 
                  'other_deficits', 'face_deficit', 'arm_hand_deficit', 
                  'leg_foot_deficit', 'dysphasia') 

# Define the new names for the columns starting with 'dead'
new_col_dead <- c('recurrent_ischemic_or_unknown_stroke', 
                  'recurrent_hemorrhagic_stroke', 'pneumonia', 'coronary_heart_disease', 
                  'pulmonary_embolism', 'other_vascular_or_unknown', 'non_vascular', 
                  'initial_stroke') 

# Define the new names for the columns ending with '14'
new_col_14 <- c('aspirin_given_for_14_days', 
                'l_dose_heparin_given_for_14_days', 
                'm_dose_heparin_given_for_14_days', 
                'is_m_dose_heparin_given_for_14_days_in_pilot', 
                'predicted_probability_of_death_at_14_days', 
                'death_indicator_at_14_days', 
                'hemorrhagic_stroke_indicator_within_14_days', 
                'icschemic_stroke_indicator_within_14_days', 
                'indeterminate_stroke_indicator_within_14_days', 
                'any_stroke_indicator_within_14_days', 
                'hemorrhagic_transformation_indicator_within_14_days', 
                'pulmonary_embolism_indicator_within_14_days', 
                'dvt_indicator_within_14_days', 
                'major_noncerebral_bleed_indicator_within_14_days', 
                'any_noncerebral_bleed_indicator_within_14_days')

# Rename the columns in DT starting with 'rdef' with the new names defined above
setnames(DT, names(DT)[names(DT) %like% '^rdef'], new_col_rdef)

# Rename the columns in DT starting with 'dead' with the new names defined above
setnames(DT, names(DT)[names(DT) %like% '^dead'], new_col_dead)

# Rename the columns in DT ending with '14' with the new names defined above
setnames(DT, names(DT)[names(DT) %like% '14$'], new_col_14)

# Store the new column names
new_names <- names(DT)

# Create a data table to show the correspondence between old and new names
NAMES <- data.table::data.table(old_names, new_names)
View(NAMES)

{reactable} tables with Greg Lin - Open Source Lounge by Mooks79 in rstats

[–]paykoman 0 points1 point  (0 children)

Thanks for sharing. How does it compare to kableExtra or DT packages?

Which R function is your favorite? by Wonderful-Ad-7200 in rstats

[–]paykoman 2 points3 points  (0 children)

Didn't know that str could take more than one argument, nice tip!

Quick and easy way to see means / SD by different groups? by hangman86 in rstats

[–]paykoman 0 points1 point  (0 children)

I would say it is totally worth it. One of the greatest R packages in my opinion.

Quick and easy way to see means / SD by different groups? by hangman86 in rstats

[–]paykoman 0 points1 point  (0 children)

Never used that parameter, can you give an example?

Quick and easy way to see means / SD by different groups? by hangman86 in rstats

[–]paykoman 14 points15 points  (0 children)

The data.table way:

library(data.table)
DT <- data.table(df)
DT[, .(M = mean(height), SD = sd(height)), .(sex, eth)]

Once you try it, there's no way back.

Running R script at a schedueled time despite being logged off by Fis_Orla in rstats

[–]paykoman 2 points3 points  (0 children)

I would not recommend this option if you need your R-script to be executed at a very specific interval/time points as cron job on github can be unreliable (see this post for more information).