Re: [R] Suppressing the Intercept in lm() when using a dataframe for the model
Well don't I feel silly now. Thanks for the help! -- View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910443.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Suppressing the Intercept in lm() when using a dataframe for the model
It's easy to run a linear regression on a simple model without an intercept just by doing this: lm(y ~ x1 + x2 -1) Is there a similar trick to suppress the intercept when your model is in a large dataframe and you don't want to write out the names of individual columns? -- View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910327.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Writing dataframes side by side in a file
Is there a quick and easy way to write data frames side-by-side in a csv file with one column separating them? I could just fill them with empty rows so they all have the same height, then cbind them with empty columns in between, but I'm looking for a more elegant solution, if one exists. Thanks in advance, Cliff -- View this message in context: http://r.789695.n4.nabble.com/Writing-dataframes-side-by-side-in-a-file-tp3649420p3649420.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rearranging columns with cbind
It's just a typo. You're missing a comma at the beginning of your index, and you should list all of the rows in a vector, like this: data[, c(19:27, 1:12, 13:15, 16:18)] The way you entered it, R is looking for rows 19:27, columns 1:12, and doesn't know what to do with the other numbers. -- View this message in context: http://r.789695.n4.nabble.com/Rearranging-columns-with-cbind-tp3466767p3466804.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What does the "<<-" operator mean?
I should probably point out that in the example, "ecov_xy " and "decay" are scalars, and x and y are vectors. -- View this message in context: http://r.789695.n4.nabble.com/What-does-the-operator-mean-tp3466657p3466672.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] What does the "<<-" operator mean?
I've been reading some code from an example in a blog post ( http://www.maxdama.com/ here ) and I came across an operator that I hadn't seen before. The author used a <<- operator to update a variable, like so: ecov_xy <<- ecov_xy+decay*(x[t]*y[t]-ecov_xy) At first I thought it was a mistake and tried replacing it with the usual <- assignment operator, but I didn't get the same results. So what does the double arrow <<- operator do? -- View this message in context: http://r.789695.n4.nabble.com/What-does-the-operator-mean-tp3466657p3466657.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating a dataframe from a vector of character strings
I have a vector of character strings that I would like to split in two, and place in columns of a dataframe. So for example, I start with this: beatles <- c("John Lennon", "Paul McCartney", "George Harrison", "Ringo Starr") and I want to end up with a data frame that looks like this: > Beatles = data.frame(firstName=c("John", "Paul", "George", "Ringo"), lastName=c("Lennon", "McCartney", "Harrison", "Starr")) > Beatles firstName lastName 1 JohnLennon 2 Paul McCartney 3George Harrison 4 Ringo Starr I tried string-splitting the first vector on the spaces between first and last names, and it returned a list: > strsplit(beatles, " ") [[1]] [1] "John" "Lennon" [[2]] [1] "Paul" "McCartney" [[3]] [1] "George" "Harrison" [[4]] [1] "Ringo" "Starr" Is there a fast way to convert this list into a data frame? Right now all I can think of is using a for loop, which I would like to avoid, since the real application I am working on involves a much larger dataset. -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-dataframe-from-a-vector-of-character-strings-tp3450716p3450716.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
The dirname() function looks very helpful; I hadn't heard of that one before. I'm still reading up to see how the parent.frame command does what it does; I didn't realize that the ofile variable might not be around in the future. Richard's suggestion -- source("c:/myfullpath/myfile.r", chdir=TRUE) -- is probably the best; I would still have to update "myfullpath" if I move myfile.r, but that's not hard to do. -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3049394.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
Thanks, Gabor! So far I like this one best: https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html So if my script is called "myRscript.r", I can do the following: this.file = parent.frame(2)$ofile this.dir = gsub("/myRscript.r", "", this.file) setwd(this.dir) This will set the working directory to the the directory that myRscript.r lives in, no matter where I move the script. It's nice that it can be done in only three lines of code, although it's not yet a perfect solution, since it won't work if I change the name of the script. But that's easy to take care of if I just do some slightly more sophisticated string manipulation (which I'm terrible at doing off the top of my head). -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3049113.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
So it sounds like the best we can do in R is to keep track of the script in a sort of master file that runs the script, and set the working directory in the master. Is that accurate? In Python any time you run a script, there is a built-in "__file__" variable that can tell you the file name of the script itself. It would be nice to have a feature like this in R. -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3048916.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking up the directory a file is located in
Basically I'm just looking for a command that can look up the name of the directory of the script that is running. If I move or copy the script to another directory, it should be able to read the name of the new directory without me having to edit the code. Once I have identified the directory, I can insert it into the setwd() command and continue with my program. -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3047878.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Looking up the directory a file is located in
Hello everyone, This should be an easy question, I think. I'd like to write a command in a program to set the working directory to whatever directory the file is currently stored in. Suppose I have a file called "myRscript.r", and it's stored in "C:\Rprojects\myRscript.r", and it references other R scripts and data files in the same directory. If I enter the command > setwd("C:/Rprojects") I can then access all the files I need without typing the path. But suppose I want to move all of those files into another folder, say, "C:\NewFolder". And suppose I might do this fairly often, or make copies of the script in several folders. Is there a command that looks something like this: > setwd( ) that will work no matter where I move my project, without having to go in and re-type the new directory path? Thanks in advance, Cliff -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3047649.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Prime Factorization
Hi everyone, I have a very quick question: Is there a ready-made function in R or any R packages to find the prime factorization of an integer? -- View this message in context: http://r.789695.n4.nabble.com/Prime-Factorization-tp2548877p2548877.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] write.csv() : attempt to set 'append' ignored... Why?
I'm running R 2.11.0 on a 32-bit Windows XP machine. Whenever I try to write a csv file with 'append' set to TRUE, I get this message: attempt to set 'append' ignored. Obviously, this is no good, since R is deleting my previously saved data files, rather than appending to them. What can I do to fix this? -- View this message in context: http://r.789695.n4.nabble.com/write-csv-attempt-to-set-append-ignored-Why-tp2290254p2290254.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Accessing files on password-protected FTP sites
Thanks for the tip. From the link you posted: | You can embed the user id and password into the URL. For example: | | http://userid:passw...@www.anywhere.com/ | ftp://userid:passw...@ftp.anywhere.com/ I'm still having issues, though. I am trying to fetch some csv files from a storage site used by my company, and I've tried the read.csv and download.file commands. These are the error messages that pop up: > read.csv("ftp://userid:passw...@ftp.anywhere.com/data.csv";) Error in file(file, "rt") : cannot open the connection > download.file("ftp://userid:passw...@ftp.anywhere.com/data.csv";, > "C:/data.csv") trying URL 'ftp://userid:passw...@ftp.anywhere.com/data.csv' Error in download.file("ftp://userid:passw...@ftp.anywhere.com/data.csv";, : cannot open URL 'ftp://userid:passw...@ftp.anywhere.com/data.csv' Am I leaving out any important options from these commands, that would allow me to access the site if I include them? When I type the URL into Firefox the same way I have entered it into R, I get the files I need. But for my particular project, I am going to have to automate the process. Obviously these are not my real userID, password, or website name. In case it is relevant, I am trying to access files that store information on the positions in my company's stock portfolio; these files are stored on our brokerage firm's website. -- View this message in context: http://r.789695.n4.nabble.com/Accessing-files-on-password-protected-FTP-sites-tp2286862p2287373.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Accessing files on password-protected FTP sites
Hello everyone, Is it possible to download data from password-protected ftp sites? I saw another thread with instructions for uploading files using RCurl, but I could not find information for downloading them in the RCurl documentation. I am using R 2.11 on a Windows XP 32-bit machine. Thanks in advance, Cliff -- View this message in context: http://r.789695.n4.nabble.com/Accessing-files-on-password-protected-FTP-sites-tp2286862p2286862.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] executable script
True, but all he said was that he wanted to auto-launch his program by double-clicking it. I don't know of any ways to speed up R other than to write the slower functions in C and then call them in your R programs. But I'm not sure that's what he had in mind. On Mon, Jun 14, 2010 at 9:19 PM, skan [via R] wrote: > Maybe he wants to compile it to an exe file in order to make it faster. > > > View message @ > http://r.789695.n4.nabble.com/executable-script-tp839859p2255307.html > To unsubscribe from Re: executable script, click here. > -- View this message in context: http://r.789695.n4.nabble.com/executable-script-tp839859p2255329.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] executable script
In Python, it is literally this easy: import rpy2.robjects as robjects robjects.r(""" source("C:/YOUR R FILE GOES HERE ") """) Type the name of your R source code into this script and save it as a Python script (add the suffix .py), and then you can run by double-clicking. If you want to see the results of your program, you'll have to have R print them in a file. Now, to get Python to run on your computer, you'll have to install the following: http://www.python.org/download/releases/2.6.5/ Python 2.6.5 http://sourceforge.net/projects/numpy/files/ NumPy 1.4.1 http://sourceforge.net/projects/rpy/files/rpy2/ Rpy2 2.0.8 (Note that these are the versions I currently have on my computer, there may be more recent ones out there.) You will also have to add Python to your computer's Path. To do this in Windows: 1. Right-click on My Computer, select Properties 2. On the Advanced tab, click Environmental Variables 3. In the System Variables list, select Path and click Edit 4. In the Variable Value line, enter "C:\Python26\;" at the beginning of the line (or "C:\Python30\" if you choose to install Python 3.0) Now you can run Python scripts simply by double clicking them. This makes it very easy to turn R codes into an executable script; the only caveat is that you need to have Python installed on any computers that you want to run your script on. -- View this message in context: http://r.789695.n4.nabble.com/executable-script-tp839859p2254813.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.