Displaying 20 results from an estimated 20000 matches similar to: "Trying to learn how to write a function... can't define a variable??"
2011 Jun 23
3
trying to import xls or xlsx files
library(xlsReadWrite)
mydata<-read.xls("file path", header=TRUE)
however if I change xls to csv it works just fine. Any ideas what I'm doing
wrong? I have have also using the package gdata with the exact same error.
Below is the error that pops up.
Error in findPerl(verbose = verbose) :
perl executable not found. Use perl= argument to specify the correct path.
Error in
2012 Jul 23
2
Bug in my code (finding nonzero min)
Can someone verify for me if the for loop below is really calculating the
nonzero min for each row of a matrix? I have a bug somewhere in the is
section of code. My first guess is how I am find the the nonzero min of each
row of my matrix. The overall idea is to make sure I am investing all of my
money, i.e. new.set is a set of indicator variables for each stock for a
particular portfolio, i.e.
2012 Jul 20
6
Speeding up a loop
General problem: I have 20 projects that can be invested in and I need to
decide which combinations meet a certain set of standards. The total
possible combinations comes out to 2^20. However I know for a fact that the
number of projects must be greater than 5 and less than 13. So far the the
code below is the best I can come up with for iteratively creating a set to
check against my set of
2012 Oct 12
3
Autofilling a large matrix in R
I wish to create a matrix of all possible percentages with two decimal place
percision. I then want each row to sum to 100%. I started with the code
below with the intent to then subset the data based on the row sum. This
works great for 2 or 3 columns, but if I try 4 or more columns the number of
rows become to large. I would like to find a way to break it down into some
kind of for loop, so
2011 Jun 06
2
qplot fill and colour not working as expected
I am just learning to use qplot and can't get the fill/colour to work. Below
is the R code for a scatter plot and bar graph.
library(ggplot2)
x<-c(1,2,3,4,5,6,7)
y<-c(1,2,3,2,5,6,3)
qplot(x,y, main="Scatter Plot Test", xlab="X Label Test", ylab="Y Label
Test", colour="blue")z<-c("van", "van", "van",
2011 Jul 12
4
qplot and for loops
I have 4 columns and 56 rows of made up data that I want to plot as a series
of bar graphs. The idea is to create one bar graph for each of the 4 columns
using a for loop. I tried the following command in RStudio and when I type x
in the console I get just the 4th graph instead of all four graphs. I did
not define what x is before hand. I was not sure what it would be. Any
suggestions on how you
2012 Sep 26
3
Removing duplicates without a for loop
I have several thousand rows of shipment data imported into R as a data
frame, with two columns of particular interest, col 1 is the entry date, and
col 2 is the tracking number (colname is REQ.NR). Tracking numbers should be
unique but on occassion aren't because they get entered more than once. This
creates two or more rows of with the same tracking number but different
dates. I wrote a for
2013 Jan 25
2
Pass vector as multiple parameters (as in python f(*x))
Hi,
I want to know if it's possible to pass a vector v=c(x,y,...) to a
function f(x,y,...) so that each vector element corresponds to a
formal argument of the function. For python programmers: f(*v).
Specifically, what I'm trying to achieve is: given a list of
coordinates l=list(c(x1,y1,z1), c(x2,y2,z2),...) I would like to
obtain the corresponding elements in some array A (3-dim in this
2013 Apr 20
1
Assigning factor to character vector
Hi!
Yesterday I accidentally discovered this:
> a <- LETTERS[1:5]
> a
[1] "A" "B" "C" "D" "E"
>
> a[1] <- factor(a[1])
> a
[1] "1" "B" "C" "D" "E"
BUT:
> b <- factor(LETTERS[1:5])
> b
[1] A B C D E
Levels: A B C D E
> b[1] <- factor(b[1])
> b
[1] A B C D E
2013 Feb 01
2
Nested loop and output help
Hello Everyone,
My name is Thomas and I have been using R for one week. I recently found
your site and have been able to search the archives of posts. This has
given me some great information that has allowed me to craft an initial
design to an inquiry I would like to make into the breakdown of McNemar's
test. I have read an intro to R manual and the posting guides and hope I am
not violating
2012 Jun 24
2
Defining multiple variables in a loop
Good day,
For lack of a better solution (or perhaps I am ignorant to something
more elegant), I have been bootstrapping panel data by hand so to
speak and I would like to know if there is a way to define multiple
variables in a loop using the loop variable. I found a post (here:
https://stat.ethz.ch/pipermail/r-help/2002-October/026305.html ) that
discussed naming multiple variables but it
2012 Sep 25
2
Recategorizing Nominal variable
Hello,
I would like to take a data set of doctors, and recategorize them into
numbers.
For example,
John Doe would be assigned as 1
Jane Doe would be assigned as 2
Does anyone know how to do this in R? It seems quite easy, yet I cannot
find the code.
Thank you,
Michael Leitson
Research Intern
MSAS Candidate
Michael.Leitson@wellstar.org
2012 Sep 01
2
(Newbie) help cannot find chrome
Following the beginning tutorial, I typed help.start() and was given a
choice of browsers. I picked chrome but got back that chrome is not found.
I cannot seem to change or get rid of it now.
I looked at /etc/R/Renviron but don't see anywhere to set browser
(R_BROWSER = ${R_BROWSER ...etc) - nothing about chrome.
I tried starting as "R_BROWSER= R" - same thing.
How do I change the
2011 Jun 21
2
qplot/ggplot2 Questions
I took some data from an online poll about which R GUI people used most and I
am messing around with it to learn how to use qplot. Specifically I am
making a horizontal bar graph and I have two questions.
1. The categories are ordered in rather strange way at least to me. It is
not alphabetical or ascending/descending order of votes cast so i had to
manually state the order I wanted which is
2011 Dec 13
2
Inverse matrix using eigendecomposition
General goal: Write R code to find the inverse matrix of an nxn positive
definite symmetric matrix. Use solve() to verify your code works.
Started with a 3x3 matrix example to build the code, but something dosen't
seem to be working. I just don't know where I am going wrong.
##Example matrix I found online
A<-c(4,1,-1,1,2,1,-1,1,2)
m<-matrix(A,nrow=3,ncol=3)
##Caculate the eigen
2012 Aug 21
2
define subset argument for function lm as variable?
Hi
I want to do a series of linear models, and would like to define the input arguments for lm() as
variables. I managed easily to define the formula arguments in a variable, but I also would like to
have the "subset" in a variable. My reasoning is, that I have the subset in the results object.
So I wiould like to add a line like:
subs <- dead==FALSE & recTreat==FALSE
which
2012 Aug 27
2
looping through numbered variables
Hello,
This is a beginner question. I am trying to loop through numbered
variables with "apply" to calculate weighted means. My data is "data",
the variables are "var1" to "var100", the weight is "weight". The
command works using
sapply(paste('data$var', 1:100, sep=''), function(x)
weighted.mean(eval(parse(text=x)), data$weight))
2012 Oct 24
2
for ( i in 23:0 ) { V <- vector [ 1 : i ] }
I'm used to run that on Matlab
>> for indice=1:23,
V=vector(1:indice)
end
that give me 23 vectors as output.
Why the same command on R " for ( i in 23:0 )
{ V <- vector [ 1 : i ] } "
returns one only vector?
How can I obtain the 23 vectors that I need ?
Thank you.
--
View this message in context:
2011 Apr 27
2
Writing Macros for RExcel
I have columns of data in Excel 2007, A2:A196, B2:B196...ET2:ET196 that I
would like to place into arrays in R. I have been trying to write a macro
that would automatically create all of my arrays for me with a array names
coming from the cells A1, B1, etc.
I can manually create an array using RExcel<Put R Var< Array, but I don't
want to manually create all 150 arrays this way.
Thanks
2013 Jan 03
1
interpreting results of regression using ordinal predictors in R
Dear friends,
Being very new to this, I was wondering if I could get some pointers
and guidance to interpreting the results of performing a linear
regression with ordinal predictors in R.
Here is a simple, toy example:
y <- c(-0.11, -0.49, -1.10, 0.08, 0.31, -1.21, -0.05, -0.40, -0.01,
-0.12, 0.55, 1.34, 1.00, -0.31, -0.73, -1.68, 0.38, 1.22,
-1.11, -0.20)
x <-