Our data in multivariate (wide) format:
my_data<- data.frame( id=c(1:50), depression1=rnorm(50), anxiety1=rnorm(50), depression2=rnorm(50), anxiety2=rnorm(50), depression3=rnorm(50), anxiety3=rnorm(50) ) my_data
Read more after the jump.
This function will extract time labeled variables (or any variables with consistent naming) by name from a data frame in the order in which they appear in the data frame. This is especially useful in cases when one has a longitudinal or time-series data set where each row (subject) has many occasions of measurements for each measure. Code and examples after the jump.
The input is specified as the row-wise lower triangle or column-wise upper triangle.
http://www.daimi.au.dk/~besen/TBiB2007/lecture-notes/rpy.html
While I've never used it, I can definitely see doing so, as I've recently become more and more a python programmer.
The function and documentation is listed after the jump.
Creating a PDF version of your graphs is very easy:
pdfname<-paste("myfilename",".pdf",sep="") pdf(pdfname, height=6.4,width=6.4) # Plotting code dev.off()
Sometimes it is the case that you know your code will produce an error---or maybe you don't know, but you don't care. This is especially troublesome in loops. Here is how to essentially ignore the error allowing you to continue on as if it never happened.
I have a rectangular data file, where one variable is a column of quoted character vectors. This variable will need to be further broken into a list of substrings, split by some delimiter. It is in the data file this way because for each observation (each subject/each row), they may have any amount of these substrings. In PHP, there is a function called explode that splits a string into an array of substrings, based on some delimiter. In R, strsplit accomplishes the same thing.
A person on the R-Help list wanted to find the mean of each group, based on ID. Their data looked like:
data<-data.frame(ID=rep(letters[1:4], 5), size=runif(20))
The person was trying to write a for loop, as most people generally do when first encountering R (I sure did), but as is the case with most procedures in R, what can be done with a for loop in other languages, can be done looplessly in R.
This is in the help files for rm, but for non-unix-ians, it seems to be hard to remember. Normally, if I am testing code that should stand on it's own, perhaps that I'll send off to the R-help list or put on here, I'll run this before I send it off:
rm(list=ls())