Last active
December 21, 2017 16:49
-
-
Save MavropaliasG/9129be5795ca02cd2df80035106c5b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download to your working directory https://github.com/MavropaliasG/R-Scripts/blob/master/Scripts/Easy%20repeated%20measures/data/mydata.csv | |
mydata <- read.csv("~/mydata.csv", stringsAsFactors=FALSE) | |
variablename <- "SquatH" # variable name, change the value in the quotation marks, case sensitive, write the name of the variable up until the time point | |
groupnames <- c("H","L") # enter group names in quotation marks and seperated by comma, e.g. c("One","Two","Three") | |
GroupColumnName <- "Group" # enter the name of the column that the Group variable is located | |
df <- data.frame(mydata) # renames the data frame | |
df[] <- lapply(df, unlist) # make the data frame not a list | |
df[df==""] <- NA # make empty cells NA | |
df[df==" "] <- NA # make empty space cells NA | |
myvar <- df[ , grepl(variablename, names( df ) ) ] # creates a new variable with all the columns that start with the name you denoted in the "x" variable | |
myvar$Group <- df[[GroupColumnName]] # creates a new column in the new variable containing the groups that are taken from the column of the original data frame | |
rm(varlist) | |
varlist <- list() | |
varlist = split(varlist, f = df[[GroupColumnName]]) # splits the original data frame into datasets by group and places them into a list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment