The first line here creates a files campnet.xlsx with a sheet in it called camp92. After I imported and prepped the network data from CSV’s. If you use Linux, as I do, there is a decent walkthrough here. Installing the xlsx package can be a trial. There are actually many packages capable of reading and writing to Excel files ( see a list here). If I were in a race with someone else to import an Excel file, I’m sure I would win nearly every time by exporting to a CSV and using read.csv than importing directly from the Excel file. The Excel integration with R can sometimes be difficult to set up. I almost always export Excel data to a CSV format. There are many good reasons to use factors, but I like to control when and how I convert strings to factors.Ĭamp92 <- read.csv ( "Camp92.txt" ) Excel ![]() Nearly always, especially when dealing with network data, you want to keep that data as text and not as factors. If you don’t use this option, or add the option to each read.csv statement, then text data will be read in as nominal factors. I almost always start with the option options(stringsAsFactors = F). Here are the Camp92.txt file and the campattr.txt files. The campattr file was exporte the same way. ![]() I created an exciting video showing how I exported the CSV file of the network data from UCINET here. In this case a value of 1 indicates the strongest relationship and the highest values indicate the weakest relationships. The Camp92 file that I import shows the rank ordering. Attendees were asked to rank order people the spent the most time with during the workshop. The dataset is called Campnet and comes from the second and third weeks of a three week workshop. If I receive other formats I usually convert them to CSV or a database if I am going to work with them frequently.įor these examples I’m going to use a dataset that I first exported to CSV file from UCINET 6. In my own work I use CSV files and databases. The CSV file is probably the easiest to work with. Comma Seperated Values (or other text formats) Let’s look at a few ways of getting data into R, but they are by no means the only ways.įinally, I’ll show how to prepare and create the graph object. That being said, some data formats are simpler to import than others. There are a great many ways of importing data into R - I have not yet encountered a data format that I could not somehow import into R. The data for this secion are found in these two files: Camp92.txt and campattr.txt. The final script for this section can be found here.
0 Comments
Leave a Reply. |