This morning I opened a new Google document that I called "Useful R Tips," but then it occurred to me that I might as well blog them. There must be other people out there in the world who are attempting to use R for stats and are equally baffled by the documentation. I thought I might have been exaggerating in this post, but it's really bad.
Here is a cute baby picture for the rest of you, and a promise to be more interesting next time.
If you have a big monster spreadsheet and you want to look at descriptive stats for some of your variables, here's what you can do. Use cbind() to stick the variables of interest together into a table, like this:
> densities2<-cbind(adv2,mor2,lf2,ccnj2,ml2)
This gives me a mini-table, called densities2, with five columns containing all my data for just the five variables I want to know more about. If you want to stick together rows and not columns, use rbind().
You can also manipulate your variables while you are sticking them into that table. I am looking at things like conjunction density, which means all my values are less than 1. I told R to multiply them by 100 so I wasn't dealing with a million tiny numbers:
> densities2<-cbind(adv2,mor2,lf2,ccnj2,ml2)*100
You can use the pastecs package to make a handy table of descriptive statistics. There is information here in English, not Klingon, on how to install the package and use the stat.desc() function.
Now suppose you want to copy your table into a word processor, or just save it to read later. Use the write.table() function, like this:
> write.table(object.name.from.stat.desc.goes.here, "directory/pick_your_filename.csv", sep=",",row.names=TRUE)
Now when you look in the directory you specified, you will see pick_your_filename.csv, which you can open up in Excel or its Open Office clone to manipulate as you please.
Recent Comments