Editing
Software Plugins and Codes
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Reading a spreadsheet into R=== Refer to http://cran.r-project.org/doc/manuals/R-intro.html#The-read_002etable_0028_0029-function . There is also a whole import/export manual for R at http://cran.r-project.org/doc/manuals/R-data.html The first step is to export your spreadsheet as a text file from your spreadsheet program. You might want to copy only the relevant columns into a new spreadsheet. If you are using Excel, I believe that you can export as a text file, although I am not certain of this. I was using Apple's Numbers. In Numbers, select the spreadsheet or the columns that you want to Export, then start up TextEdit. Make sure that the new blank text document is plain text (Format -> Make Plain Test), then Paste in the spreadsheet. This resulted in a text file in exactly the right format for importing into R, like this cage fnbmd10 20 0.72 20.1 0.74 20.1 1.02 20.2 0.97 20.2 0.84 20.4 0.69 20.4 0.98 20.5 20.6 0.82 It may happen that there are some missing data in your columns (as in the above example). This command (from the command line) will copy all lines from file fnbmd10.data to file fnbmd10_trimmed.data that have exactly two fields, which is what we want: awk '(NF==2) {print $0}' fnbmd10.data > fnbmd10_trimmed.data If you have a column for sex, and you want to split it into two files, one for each sex, you can do this: awk '($2==0) {print $0}' input.txt > output_w.txt awk '($2==1) {print $0}' input.txt > output_m.txt In this example, the sex is the second field (hence $2). You will need to manually add the column headings again after doing this. Once your text file looks correct, you can load it into R with the following command (from within R obviously): dataframe <- read.table("fnbmd10_trimmed.data", header=TRUE) I recommend at this point using some of R's graphical capabilities to plot and examine the data, just to make sure it seems to be reasonable. plot (dataframe$cage, dataframe$fnbmd10) ====Tip: Setting the Working Directory in R==== setwd("/Users/eric/Documents/change_point") ====Tip: Converting line endings==== In case it's required, this can be done from a command prompt in OS-X or Linux: cat input.txt | tr '\r' '\n' > output.txt
Summary:
Please note that all contributions to bone.wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BoneWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
associated-pages
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Documents
Recent changes
Help
Tools
What links here
Related changes
Page information