Displaying 20 results from an estimated 20000 matches similar to: "How to dynamically add variables to a dataframe"
2018 Apr 22
0
How to dynamically add variables to a dataframe
Hi Luca,
How about this?
# create some dummy data since I don't have your d0 or d1
> n <- 3
> d0 <- data.frame(a=runif(5),b=runif(5))
# here's the suggested code
> d1 <- cbind(d0, matrix(0,nrow(d0),n))
> colnames(d1)[1:n + ncol(d0)] <- paste("V",1:n,sep="")
HTH,
Eric
On Sun, Apr 22, 2018 at 11:13 AM, Luca Meyer <lucam1968 at
2018 Apr 30
3
How to visualise what code is processed within a for loop
Luca,
If speed is important, you might improve performance by making d0 into a true matrix, rather than a data frame (assuming d0 is indeed a data frame at this point). Although data frames may look like matrices, they aren?t, and they have some overhead that matrices don?t. I don?t think you would be able to use the [[nm]] syntax with a matrix, but [ , nm] should work, provided the matrix has
2018 Apr 24
4
How to visualise what code is processed within a for loop
Hi,
I am trying to debug the following code:
for (i in 1:10){
t <- paste("d0$V",i,sep="")
t <- ifelse(regexpr(d1[i,1],d0$X0)>0,1,0)
}
and I would like to see what code is actually processing R, how can I do
that?
More to the point, I am trying to update my variables d0$V1 to d0$V10
according to the presence or absence of some text (contained in the file
d1)
2018 Apr 28
2
How to visualise what code is processed within a for loop
I forgot to explain why my suggestion.
The logical condition returns FALSE/TRUE that in R are coded as 0/1.
So all you have to do is coerce to integer.
This works because the ifelse will return a 1 or a 0 depending on the
condition. Meaning exactly the same values. And is more efficient since
ifelse creates both vectors, the true part and the false part, and then
indexes those vectors in
2018 Apr 30
0
How to visualise what code is processed within a for loop
Hi Rui
Thank you for your suggestion,
I have tested the code suggested by you against that supplied by Don in
terms of timing and results are very much aligned: to populate a 5954x899
0/1 matrix on my machine your procedure took 79 secs, while the one with
ifelse employed 80 secs, hence unfortunately not really any significant
time saved there.
Nevertheless thank you for your contribution.
2018 Apr 30
0
How to visualise what code is processed within a for loop
Thank you for both replies Don & Rui,
The very issue here is that there is a search that needs to be done within
a text field and I agree with Rui later comment that regexpr might indeed
be the time consuming piece of code.
I might try to optimise this piece of code later on, but for the time being
I am working on the following part of building a neural network to try
indeed classifying some
2018 Apr 28
2
How to visualise what code is processed within a for loop
Thanks Don,
for (i in 1:10){
nm <- paste0("V", i)
d0[[nm]] <- ifelse( regexpr(d1[i,1], d0$X0) > 0, 1, 0)
}
is exaclty what I needed.
Best regards,
Luca
2018-04-25 23:03 GMT+02:00 MacQueen, Don <macqueen1 at llnl.gov>:
> Your code doesn't make sense to me in a couple of ways.
>
> Inside the loop, the first line assigns a value to an
2018 Apr 24
0
How to visualise what code is processed within a for loop
The loop never assigns anything to d0, only t. The first line makes t
a character string "d0$V1" (or "d0$V2" etc.). The second line assigns
either 0 or 1 to t.
Looking at this, I don't think you've got into the R psychology (bad
news if you want to use R, good news in many other ways). I assume d0
is a list, so could you put the V's into a vector, and then just use
2018 Apr 28
0
How to visualise what code is processed within a for loop
Hello,
instead of ifelse, the following is exactly the same and much more
efficient.
d0[[nm]] <- as.integer(regexpr(d1[i,1], d0$X0) > 0)
Hope this helps,
Rui Barradas
On 4/28/2018 8:45 PM, Luca Meyer wrote:
> Thanks Don,
>
> for (i in 1:10){
> nm <- paste0("V", i)
> d0[[nm]] <- ifelse( regexpr(d1[i,1], d0$X0) > 0, 1, 0)
> }
2018 Apr 25
0
How to visualise what code is processed within a for loop
Your code doesn't make sense to me in a couple of ways.
Inside the loop, the first line assigns a value to an object named "t".
Then, the second line does the same thing, assigns a value to an object named "t".
The value of the object named "t" after the second line will be the output of the ifelse() expression, whatever that is. This has the effect of making
2012 Aug 06
5
regexpr with accents
Hello,
I have build a syntax to find out if a given substring is included in a larger string that works like this:
d1$V1[regexpr("some text = 9",d1$V2)>0] <- 9
and this works all right till "some text" contains standard ASCII set. However, it does not work when accents are included as the following:
d1$V1[regexpr("some t?xt = 9",d1$V2)>0] <- 9
I have
2017 Dec 29
3
Writing text files out of a dataset
Hello,
I am trying to run the following syntax for all cases within the dataframe
"data"
d1 <- data[1,c("material")]
fileConn<-file("TESTI/d1.txt")
writeLines(d1, fileConn)
close(fileConn)
I am trying to use the for function:
for (i in 1:nrow(data)){
d[i] <- data[i,c("material")]
fileConn<-file("TESTI/d[i].txt")
2011 Feb 09
1
Adding labels into lattice's barchart
*** APOLOGIZES FOR THOSE READING THE LIST THROUGH NABBLE THIS WAS ALREADY POSTED THERE BUT NOT FORWARDED TO THE LIST FOR SOME UNKNOWN REASON ***
I have a dataset that looks like:
$ V1: factor with 4 levels
$ V2: factor with 4 levels
$ V3: factor with 2 levels
$ V4: num (summing up to 100 within V3 levels)
$ V5: num (nr of cases for each unique combination of V1*V2*V3 levels)
Quite new to
2011 Aug 28
4
How do I get a weighted frequency table?
? stato filtrato un testo allegato il cui set di caratteri non era
indicato...
Nome: non disponibile
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110828/d35f51a1/attachment.pl>
2012 Nov 30
3
Reading .gsheet within R
Hello R-experts,
I would like to know if there is a solution to read files with extension .gsheet directly into R - see http://www.fileinfo.com/extension/gsheet for more info on this file format.
Thank you,
Luca
Mr. Luca Meyer
www.lucameyer.com
R 2.15.1
Mac OS X 10.8.2
[[alternative HTML version deleted]]
2002 Apr 30
3
rbind'ing empty rows in dataframes in 1.4.1 versus 1.5.0
Hi,
In 1.4.1, I was able to create extra "empty" rows in a dataframe as so:
> x <- data.frame(a = letters[1:3], b = 1:3)
> x
a b
1 a 1
2 b 2
3 c 3
> x[4,]
a b
NA NA NA
> rbind(x, x[4,])
a b
1 a 1
2 b 2
3 c 3
NA NA NA
> R.version
_
platform sparc-sun-solaris2.6
arch sparc
os solaris2.6
2012 Aug 30
4
Leading plus in numeric fields
Hello R experts,
I have go this data frame:
'data.frame': 1 obs. of 20 variables:
$ Anno : chr "PREVISIONI VS TARGET"
$ OreTot: num 41
$ GioTot: logi NA
$ OrGTot: logi NA
$ OreCli: num 99
$ GioCli: logi NA
$ OrGCli: logi NA
$ OreFor: num -27
$ GioFor: logi NA
$ OrGFor: logi NA
$ OreOrt: num -18
$ GioOrt: logi NA
$ OrGOrt: logi NA
$ OreSpo: num -6
$ GioSpo: logi
2017 Jun 27
4
My experience using -DLLVM_BUILD_INSTRUMENTED_COVERAGE to generate coverage
With llc, the size of the names section can vary widely depending on the value of -DLLVM_TARGETS_TO_BUILD.
Enabling coverage shouldn't increase the name section size much. I only see one place where this happens, and it's relatively cold:
http://lab.llvm.org:8080/coverage/coverage-reports/llvm/coverage/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R at
2003 Oct 16
3
indexing a particular element in a list of vectors
I have a "list" of character vectors. I'm trying to see if there is a way
(in a single line, without a loop) to pull out the first element of all the
vectors contained in the list.
listOfVectors[1:length(listOfVectors][1]
doesn't work.
==========================
If you want more details..
Here is my listOfVectors which is called "uuu"
>
2017 Jun 27
2
My experience using -DLLVM_BUILD_INSTRUMENTED_COVERAGE to generate coverage
I had an old build of llc with FE instrumentation, the name section size is
about 5MB. Using coverage is likely to cause the name section to be larger
as there are more references to dead/unused function names.
What do you see when
readelf --string-dump=__llvm_prf_names llc
David
On Tue, Jun 27, 2017 at 2:23 PM, Xinliang David Li <davidxl at google.com>
wrote:
>
>
> On Tue,