Displaying 20 results from an estimated 60000 matches similar to: "simple problem"
2005 Mar 01
2
part of name to Date
hi everybody,
i try to extract a part of name to a date :
like : "VGT1_VGT2_CONTR_B020030401.H0V0.MIR" to "20030401"
but the beginning of the files changes
i have a list of files:
[,1]
[1,] "VGT1_CONTR_B020020301.H0V0.MIR"
[2,] "VGT1_VGT2_CONTR_B020020611.H0V0.MIR"
[3,]
2005 Mar 17
1
error in solve_technical question
Hi everybody,
it's a technical question .
i have a matrix with 30 columns and 40000 rows,
i start my program and i found this error:
"error in solve.default(sBB + Z[,,i] %*% Gamma %*% t(Z[,,i])):
system is computationally singular: reciprocal condition number =
7.6377e-018 "
is it R limit?
thanks a lot.
Jonathan Charrier
2011 Jan 15
3
get list element names within lapply / sapply call
Hi all,
I would like to iterate through a list with named elements and access the
names within an lapply / sapply call. One way to do this is iterate through
the names and index the list with the name. Is there a way to iterate
through the list elements themselves and access the element names within in
the function? For example,
mylist <-
2018 Mar 29
0
Creating the right table from lapply list
Perhaps this toy example will help:
## example data
output <- list(1:5, 1:7, 1:4)
lens <- lapply(output, length)
maxlen <- max(unlist(lens))
outputmod <- lapply(output, function(x, maxl) c(x, rep(NA, maxl-length(x))), maxl=maxlen)
outputmat <- do.call(cbind, outputmod)
write.csv(outputmat, na='')
The idea is to pad the shorter vectors with NA (missing) before converting
2005 Apr 29
2
how to replace text...
if I have....
QQQQ<-priceIts("QQQQ",quote="Close")
QQQQ<-priceIts("QQQQ",quote="Close");plot(QQQQ)
and then i want to do the same thing but say with IBM instead of QQQQ
is there an easy way like replace qqqq/ibm
Thanks in advance./Jonathan
2003 Oct 16
2
returning dynamic variable names from function
Within a function I'm assigning dynamic variable names and values to them
using the "assign" function. I want to pass back the results but am
uncertain how to do this.
Basically, my function reads a number of data files and uses the filename of
each file as the variable name for a list-to-become-dataframe. I want then
to pass all these lists back, but again, the names of the
2018 Mar 28
3
Creating the right table from lapply list
Hello,
I have no previous experience with R, but had to learn on the fly in the past couple of weeks. Basically, what I am trying to do is read a certain variable from a series of files and save it as csv-table. The variable has an hourly value for each month in a year for the past 20 years and has to be read for different geographical locations. So there will be 12 files per year (1 for each
2004 Mar 11
3
making operators act on rows of a data frame
Dear R helpers,
I wish to use the "sum" operator for each row of a data frame.
However, it appears that the operator acts on the entire data
frame, over all columns. What is the best way to obtain row-
wise operation?
The following code shows my attempts so far, and their problems:-
test1=array(rbinom(120,1,0.5),c(20,3))
test1[,3]=NA
sum(test1[,1:2])
test1[,3][sum(test1[,1:2])>=2]=1
2009 Oct 23
2
splitting a vector of strings...
Quick question -- if I have a vector of strings that I'd like to split
into two new vectors based on a substring that is inside of each string,
what is the most efficient way to do this? The substring that I want to
split on is multiple characters, if that matters, and it is contained in
every element of the character vector.
--j
--
Jonathan A. Greenberg, PhD
Postdoctoral Scholar
2012 Mar 28
2
lapply and paste
I have a list of suffixes I want to turn into file names with extensions.
suff<- c("C1", "C2", "C3")
paste("filename_", suff[[1]], ".ext", sep="")
[1] "filename_C1.ext"
How do I use lapply() on that call to paste()?
What's the right way to do this:
filenames <- lapply(suff, paste, ...)
?
Can I have lapply()
2008 Dec 13
1
simple list question
I'd appreciate some tips, I'm making a simple mistake trying to
extract elements from a list of fit objects.
The following command works, coef( cph.list[[1]] ) ,.... coef(
cph.list[[3]] ) and so forth. These extract regression coefficients
from the appropriate list element.
When I try to run this inside a for loop, or an lapply
(lapply(cph.list,coef)) I get this error
2009 Jun 18
1
Stratified random sampling?
Rers:
What is the preferred library/function for doing stratified random
sampling from a dataset, given I want to control the number of samples
(rather than the proportion of samples) per strata? Thanks!
--j
--
Jonathan A. Greenberg, PhD
Postdoctoral Scholar
Center for Spatial Technologies and Remote Sensing (CSTARS)
University of California, Davis
One Shields Avenue
The Barn, Room
2020 Feb 26
1
Profiling: attributing costs to place of invocation (instead of place of evaluation)?
Hi
Consider the following example:
f <- function(expr) g(expr)
g <- function(expr) {
? h(expr)
}
h <- function(expr) {
? expr # evaluation happens here
? i(expr)
}
i <- function(expr) {
? expr # already evaluated, no costs here
? invisible()
}
rprof <- tempfile()
Rprof(rprof)
f(replicate(1e2, sample.int(1e4)))
Rprof(NULL)
cat(readLines(rprof), sep = "\n")
#>
2006 May 11
3
cannot turn some columns in a data frame into factors
Hi,
I have a data frame df and a list of names of columns that I want to
turn into factors:
df.names <- attr(df,"names")
sapply(factors, function (name) {
pos <- match(name,df.names)
if (is.na(pos)) stop(paste(name,": no such column\n"))
df[[pos]] <- factor(df[[pos]])
cat(name,"(",pos,"):",is.factor(df[[pos]]),"\n")
2015 Feb 24
2
iterated lapply
> On Feb 24, 2015, at 10:50 AM, <luke-tierney at uiowa.edu> wrote:
>
> The documentation is not specific enough on the indented semantics in
> this situation to consider this a bug. The original R-level
> implementation of lapply was
>
> lapply <- function(X, FUN, ...) {
> FUN <- match.fun(FUN)
> if (!is.list(X))
> X <-
2005 Jul 22
1
sapply(NULL, ...) returns a list?!?
Hi,
I bet this one has be asked before, but doing
sapply(x, FUN=as.character)
where 'x' is a vector, then the result "should [] be simplified to a
vector" according to ?sapply, correct? However,
> x <- 1:10
> sapply(x, FUN=as.character)
[1] "1" "2" "3" "4" "5" "6" "7" "8"
2017 Mar 28
2
A trap for young players with the lapply() function.
On 28/03/17 15:26, Charles C. Berry wrote:
> On Mon, 27 Mar 2017, Rolf Turner wrote:
>
>>
>> From time to time I get myself into a state of bewilderment when using
>> apply() by calling it with FUN equal to a function which has an
>> "optional" argument named "X".
>>
>> E.g.
>>
>> xxx <-
2009 Mar 13
2
Using format to add leading zeroes
I have a numerical vector which contains a (poorly) formatted time
column, which, in theory, should be HHMM, but was distributed as an
integer, so, for 12:15 am, it is saved as "15" (e.g. HHMM = 0015 with
the zeroes stripped). I'm trying to use this in conjunction with
strptime, but I'm thinking because each time is an integer ranging from
1 to 4 digits, I probably need to
2010 Jan 26
1
splitting a factor column into binary columns for each factor
Yesterday I posted the following question (my apologies for not putting a subject line):
=================question======================
Hello -- I would like to know of a more efficient way of writing the following piece of code. Thanks.
options(stringsAsFactors=FALSE)
orig <- c(rep('11111111',100000),rep('22222222',200000),rep('33333333'
2003 Aug 11
4
subscripts in lists
I am tying myself in knots over subscripts when applied to lists
I have a list along the lines of:
lis<-list(c("a","b","next","want1","c"),c("d", "next", "want2", "a"))
>From which I want to extract the values following "next" in each
member of the list, i.e. something along the lines of