similar to: weird apply() behavior

Displaying 20 results from an estimated 30000 matches similar to: "weird apply() behavior"

2008 Aug 18
2
ifelse
I find it slightly surprising, that ifelse(TRUE, character(0), "") returns NA instead of character(0). [WNT 2.6.2 Patched] -- Heikki Kaskelma
2007 Feb 01
3
Can this loop be delooped?
Hi. I have the following code in a loop. It splits a vector into subvectors of equal size. But if the size of the original vector is not an exact multiple of the desired subvector size, then the first few subvectors have one more element than the last few. I know that the cut function could be used to determine where to break up the vector, but it doesn't seem to provide control over
2006 Sep 25
1
apply: new behaviour for factors in R-2.4.0
Dear R-core There is a different output for the apply function due to the change of unlist as mentioned in the R news. Newly, applying as.factor() (or factor()) in str(dat <- data.frame(x = 1:10, f1 = gl(2,5,labels = c("A", "B")))) (d1 <- apply(dat,2,as.factor)) newly returns a character matrix while in R-2.3.1 the same command resulted in an integer matrix that was
2005 Apr 21
2
apply vs sapply vs loop - lm() call appl(y)ied on array
Christoph -- There was just a thread on this earlier this week. You can search in the archives for the title: "refitting lm() with same x, different y". (Actually, it doesn't turn up in the R site search yet, at least for me. But if you just go to the archive of recent messages, available through CRAN, you can search on refitting and find it. The original post was from William
2007 Feb 28
2
delete selecting rows and columns
Hi, I'm working with a big square matrix (15k x 15k) and I have some trouble. I want to delete selecting rows and columns. I'm using something like this: > sel_r=c(15,34,384,985,4302,6213) > sel_c=c(3,151,324,3384,7985,14302) > matrix=matrix[-sel_r,-sel_c] but it works very slow. Does anybody know how to make it in faster way? Thank's -- View this message in context:
2007 Jan 17
2
problem with unlist POSIX date at midnight
Dear R-users, I use unlist of POSIX dates to extract the year, hour etc. With that I can search for files in my database which are in the form 'yyyymmddhh_synops.txt' However, I get stucked during midnight where unlist just gives NA's. The script is given below, the problem accurs at acc.period[16] (midnight). However when I write out the character, unlist works well. But
2011 May 19
1
Feature request: extend functionality of 'unlist()' by args 'delim=c("/", "_", etc.)' and 'keep.special=TRUE/FALSE'
Dear list, I hope this is the right place to post a feature request. If there's exists a more formal channel (e.g. as for bug reports), I'd appreciate a pointer. I work a lot with named nested lists with arbitrary degrees of "nestedness". In order to retrieve the names and/or values of "bottom layer/bottom tier", I love the functionality of 'unlist()', or
2008 Feb 29
2
while loop syntax help
Dear list, I'm trying to write my first looping function in R. After many hours of searching help files and previous posts, I'm at wits end. Please forgive my programming ignorance...any help is greatly appreciated. I need to sort through a vector (x) and identify the point at which 2 successive values become smaller than the previous value. I've written a "while"
2010 Jul 29
1
Using 'dimname names' in aperm() and apply()
I think that the "dimname names" of tables and arrays could make aperm() and apply() (and probably some other functions) easier to use. (dimname names are, for example, created by table() ) The use would be something like: -- x <-table( from=sample(3,100,rep=T), to=sample(5,100,rep=T)) trans <- x / apply(x,"from",sum) y <- aperm( trans,
2008 Jun 12
2
numbers as part of long character
Hi, I'm looking for some way to pick up the numbers which are contained and buried in a long character. For example, outtree.new="(((B:1204.25,E:1204.25):7581.11,F:8785.36):8353.85,C:17139.21);" num.char =
2011 Oct 05
1
Vector-subsetting with ZERO - Is behavior changeable?
Dear All, I have trouble generizising some code. > index <- 0 > sapply(list(c(1,2,3),c(1,2),c(1)),function(x){x[max(length(x)-index,0)]}) Will yield a wished for vector like so: [1] 3 2 1 But in this case (trying to select te second to last element in each vector of the list) > index <- 1 > sapply(list(c(1,2,3),c(1,2),c(1)),function(x){x[max(length(x)-index,0)]}) I end up
2009 Apr 01
1
Vector of Vectors
I have a matrix of data. I need to scan the matrix and find every sequence from maxima to maxima across a row. I can write a loop to do this easily. Problem is, I can't figure out how to store the results. Each result is a vector of widely varying lengths. Ideally I'd like a vector of these, i.e. a vector of vectors, so I can quickly iterate through them and compute correlation
2012 Jun 19
1
need help with unlist(), losing NULL values
Hi, I have a very rudimentary kind of question on using unlist(). I am parsing a bunch of JSON text using rjson package. Some data elements in a dictionary happen to be null which rjson parses correctly. > fromJSON(json_str='{"query":{"A":10, "B":null, "C":"hello"}, "query":{"A":20, "B":null,
2013 Sep 27
2
Locating inefficient code
Hi, I have been using R for a few months and I have this working code. Don't seen any problem but this takes a long time. So if I have about 30000 rows it takes a few minutes. If I have 100000 it does not seem to complete. Original Data: Proto Recv-Q Send-Q Local-Address Foreign-Address State tcp 0 0 172.20.100.2:60255
2017 May 10
2
bug report: nlme model-fitting crashes with R 3.4.0
lme() and gls() models from the nlme package are all crashing with R.3.4.0. Identical code ran correctly, without error in R 3.3.3 and earlier versions. The behavior is easily demonstrated using one of the examples form the lme() help file, along with two simple variants. I have commented the errors generated by these calls, as well as the lines of code generating them, in the code example below.
2011 Mar 19
2
persuade tabulate function to count NAs in a data frame
Hi, I'd like to ask you a question again. It is basically about data frames, NAs and tabulate function. I have this data frame. I already used this in one of the previous questions of mine. It intentionally looks this simple, my real 'df' dataframe is much bigger actually and again, I am not willing to annoy anyone with huge databases... So, my database: id
2007 Mar 27
3
Unexpected result of as.character() and unlist() applied to a data frame
Hi, > dd <- data.frame(A=c("b","c","a"), B=3:1) > dd A B 1 b 3 2 c 2 3 a 1 > unlist(dd) A1 A2 A3 B1 B2 B3 2 3 1 3 2 1 Someone else might get something different. It all depends on the values of its 'stringsAsFactors' option: > dd2 <- data.frame(A=c("b","c","a"), B=3:1, stringsAsFactors=FALSE) > dd2
2002 Sep 18
2
More on list to data frame (was: Re: List to Data Frame
Hi, Now suppose I have just one list called FOO, which has 25 objects, e.g.: [[1]] 1 2 3 4 5 [[2]] 6 7 8 9 10 . . . And I want to do something like: FRED <- data.frame(cbind(unlist(FOO[[1]]), unlist(FOO[[2]]), # ... for all 25 subsets )) Is it possible to do this, without doing unlist(FOO[[i]]) 25
2018 Feb 25
0
include
Hi Val, My fault - I assumed that the NA would be first in the result produced by "unique": mydat <- read.table(textConnection("Col1 Col2 col3 Z1 K1 K2 Z2 NA NA Z3 X1 NA Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE) val23<-unique(unlist(mydat[,c("Col2","col3")])) napos<-which(is.na(val23)) preval<-data.frame(Col1=val23[-napos],
2018 Feb 25
0
include
hi Val, Your problem seems to be that the data are read in as a factor. The simplest way I can think of to get around this is: mydat <- read.table(textConnection("Col1 Col2 col3 Z1 K1 K2 Z2 NA NA Z3 X1 NA Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE) preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1], Col2=NA,col3=NA) rbind(preval,mydat)