Posts by Marcos Banik • 1,779 points
45 posts
-
0
votes2
answers54
viewsA: Unexpected exit
You can do this using apernas the Sort. sort -u arquivo.csv -o arquivo.csv -u will remove duplicate lines -o will send the output to the.csv file…
-
2
votes2
answers144
viewsA: Create an object that contains four words. Use the sample function to sample 1000 values of that object
Are you sure you copied the right code? It’s not something like: pal <- c("oi","ola","hey","hi") palavreado <- sample(pal,1000, replace=TRUE) table(palavreado) palavreado hey hi oi ola 251 245…
-
2
votes1
answer883
viewsA: Create a data sequence from 1 to 30 only with odd numbers. Use the seq() function
Just pay attention to the parameters. seq(from = 1, to = 30, by = 2) from: beginning of the sequence to: maximum possible value of the sequence. Not quite the final element. by: sequence increment.…
ranswered Marcos Banik 1,779 -
4
votes1
answer57
viewsA: I cannot maintain the format of a date received from a dataframe
You’re right. The date is the number of days since the "Unix season". To get the date in the format you want: as.Date("1970-01-01", format = "%Y-%m-%d") + 17160 [1] "2016-12-25"…
-
0
votes1
answer770
viewsA: Floating table for new page
Try eliminating the second load of placeins in \usepackage[section]{placeins} \usepackage{placeins} Maybe that erased the option section of the first call. If it doesn’t work, try to force before…
latexanswered Marcos Banik 1,779 -
3
votes2
answers817
viewsA: Overlay graphics in R with ggplot
I think I understand what you want to do. # Vou mudar o seu df2. df2 <- data.frame(turma = c("Q.1", "Q.2", "Q.3", "Q.4", "Q.5", "Q.6"), gabarito = factor(c("B", "A", "C", "D", "A", "C"), levels =…
-
3
votes1
answer175
viewsA: How to loop to generate graphics in R?
I don’t think the loop is the best solution for your case. # alongue o data frame. library(tidyr) long <- df %>% gather(turma, quantidade, Q.1:Q.6) # use facet_wrap library(ggplot2)…
-
2
votes2
answers385
viewsA: Problem with C matrices
All loops are wrong indexes. first loop int n_alunos = 6; int n_notas = 4; for(i=0; i != n_alunos; i++) { for(j=0; j != n_notas; j++) { printf("\nAluno %d Nota %d \n", i, j); scanf("%f",…
-
0
votes3
answers238
viewsA: Remove all after ? in file name
You can try replacing parameters in bash. If there is no '?' in something. Remove from $f the shortest way to find the pattern ? for f in *; do mv -v "$f" "${f%\?*}" ; done If there is no '?' in…
-
2
votes1
answer123
viewsA: Is there any R function that can convert dates?
Kicking over data from a sensor I don’t know. The data can make some sense if: 1. The timestamp is recording in milliseconds; 2. They show the time needed to measure n samples. To get timestamp time…
ranswered Marcos Banik 1,779 -
1
votes1
answer467
viewsA: Error in scan (file=file, what=what...)
The problem is that your header has column names with spaces. You have some options. Changes the file. The best, but not always possible. Ignore the header. And enter the names. Base =…
ranswered Marcos Banik 1,779 -
0
votes1
answer28
viewsA: How to make a shell file create a php page
something like #!/bin/bash cat << EOF > /var/www/html/teste.php <?php echo "Funcionou?"; ?> EOF should work.
-
3
votes3
answers743
viewsA: Count of TRUE and FALSE
I would use the function table x <- c(TRUE, TRUE, FALSE) table(x) Upshot: x FALSE TRUE 1 2
-
2
votes1
answer186
viewsA: How to pick a pointer from a class c++ vector
From c++11 you can use the function date. It returns the address of the array used to store the vector elements. Note that if the vector has no elements, data() may or may not return nullptr…
-
6
votes1
answer1795
viewsA: how to undo "git checkout" from a specific commit and go back to the last commit I did before checkout
Try using git reflog. You should have a listing like: 220981e HEAD@{0}: checkout: moving from master to 220981e 239b47a HEAD@{1}: checkout: moving from c_api to master This indicates that at the…
-
5
votes2
answers552
viewsQ: R - Selecting elements of a data frame with a column that has the same name as a global variable with`dplyr`
Consider the following data.frame and the variable x df <- data.frame(x = c(rep(0, 10), rep(1, 10)), y = 1:20) x <- 0 I tried to use the dplyr to select column elements x equal to the global…
rasked Marcos Banik 1,779 -
0
votes1
answer38
viewsA: Excerpt execution time of a code with an accuracy greater than 0.001 seconds
I believe the problem is on the line duration<double> time_span = duration_cast<duration<double,nano>>(t4 - t3); You forgot to std::nano and lowered the resolution to seconds.…
c++answered Marcos Banik 1,779 -
2
votes2
answers340
viewsA: Refection return in C++
Maybe there are other possibilities. But one of them is a pointer to the first element of the array data of the object of a class implementing the member function begin(). this refers to the pointer…
-
0
votes2
answers44
viewsA: how to implement the jaccknife method if two terms are removed (in R)
I’ll help you find var2 and Tn. From then on I didn’t understand what you did. #Todas as combinações de índices de 10 elementos tomados 8 a 8. idx <- t(combn(10, 8)) #Todas as sub-amostras de 8…
-
0
votes3
answers95
viewsA: Identify a specific word in a C++ String, is there a function ready for that? Or just in the nail itself?
regex_replace may be what you seek. #include <iostream> #include <regex> #include <string> int main() { std::string line1{"Depende: lsb-release"}; std::string line2{"Independe:…
-
2
votes1
answer221
viewsA: Fill cells with AN by an annual logical sequence in R
I don’t understand what you’re up to with this, but it seems like all the information you need is on idade_2012 To fill the other columns just do id<-c(1:25) idade_2012 <- c(21, 18, 19, 25,…
-
3
votes1
answer292
viewsA: Ignoring files in git that don’t have an extension
The trick is to ignore everything and then delete the files you want # ignore tudo * # exclua os subdiretórios !/**/ # exclua os arquivos com extensão !*.* But I don’t recommend doing this. Default…
gitanswered Marcos Banik 1,779 -
3
votes2
answers171
viewsA: Identify cases with multiple conditions in multiple columns in R
using the function rowSums to get the table as you requested fluxo$dois_ou_mais <- as.numeric(rowSums(fluxo[,-1] == 43, na.rm = TRUE) > 1) But if you are interested in getting only students,…
-
1
votes2
answers3944
viewsA: How to transpose rows into columns in a data frame?
I’m not sure if it’s what you want, but you can try using the library tidyr library(tidyr) spread(df, mes, prec) ID dia ano ago set 1 1 21 1961 NA NA 2 2 22 1961 0 NA 3 3 23 1961 1 NA 4 4 24 1961 0…
ranswered Marcos Banik 1,779 -
3
votes1
answer67
viewsQ: How to transfer a table from the clipboard to a R data.frame
Motivation In various language questionsRI see people putting the contents of a table instead of showing the steps to reproduce the data they’re analyzing. Requests to provide the result of the…
rasked Marcos Banik 1,779 -
1
votes2
answers349
viewsA: How to insert missing dates into a data frame?
one option is to use the library padr dados <- structure(list( date = structure(c(-3058, -3054, -3052, -3051, -3050, -3049, -3047, -3046), class = "Date"), id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),…
ranswered Marcos Banik 1,779 -
2
votes4
answers801
viewsA: How to use switch in C?
switch(opt) informs that the variable opt will be used to compare with the values after each case. Each break signals that the control should go outside the block switch. So even though it’s not…
-
2
votes2
answers465
viewsA: Is there a function that checks if a certain value is contained in a certain range?
The closest I found was the function findInterval. You can try something like: x.int <- (findInterval(x, limites, rightmost.closed = TRUE) == 1) But I honestly see no reason for you to stop using…
-
1
votes2
answers68
viewsA: Linux running average
To get just the time, you can use date t0=$(date +%s) for i in {1..5}; do sleep 1; done tf=$(date +%s) echo "tempo de execução: $((tf - t0))" To use the team the way you tried, you need to put the…
-
6
votes4
answers5695
viewsA: Get list of changed files in working directory (Working directory)
I get the impression that you only want the modified files. No "untracked" or "staged" files. In this case use git ls-files --modified or git ls-files -m Obs: the files in the index have not been…
gitanswered Marcos Banik 1,779 -
3
votes1
answer596
viewsA: Unify column the dataset and place this content below a table
It’s not exactly what you want, but I think it might help you. I will assume the following data.frame. Posting the expected result helps, but it would help more if you provided a more complete…
ranswered Marcos Banik 1,779 -
3
votes3
answers7816
viewsA: Separate contents from one column in other columns
The biggest difficulty is providing names for the new columns. I will adopt the same variable file and the same scheme for column names that Molx used. If you know beforehand the number of columns…
ranswered Marcos Banik 1,779 -
7
votes1
answer339
viewsQ: How to declare constants in R
when I went to reproduce the example of the question "How to turn a string into Date format in R?" the command tab<-readHTMLTable(u,header=T,skip.rows=1) failed. The error happened because in my…
-
4
votes2
answers4567
viewsA: How to turn a string into Date format in R?
To store Dataano as Date you can change the last line to dados$DataAno <- as.Date(paste(ano, dados$Date), format = "%Y %b %d") the parameters of format serve to indicate that the string is in the…
-
3
votes1
answer1334
viewsA: Git accuses that ignored directory has modified content
This message may appear if dir is a sub-module of your repository. You can check this by running git submodule in your root repository. In case you want to git status ignore the changes in app/dir…
gitanswered Marcos Banik 1,779 -
1
votes1
answer377
viewsA: Define multiple variables in one row only
I’m not sure it’ll work for your case. tripa="meu host,127.0.0.1,abc" IFS=',' read hostname ip serial <<<"$tripa" echo -e "$hostname\n$ip\n$serial" I found that answer here…
-
10
votes2
answers2443
viewsQ: How to smooth a curve in R
The goal is to get the smoothed chart from data frame. x <- c(1e-04, 0.0014, 0.018, 0.24, 3.2, 42, 560, 7500, 1e+05) y <- c(0, 7, 10, 7, 0, -7, -10, -7, 0) df <- data.frame(x, y) The curve…
-
11
votes5
answers12797
viewsA: How to consolidate (aggregate or group) the values in a database?
You can do this with the function aggregate aggregate(vendas ~ vendedor, data=df, FUN=sum) vendedor vendas 1 A 3300 2 B 440 3 C 1020 4 D 200 aggregate(vendas ~ vendedor + regiao, data=df, FUN=sum)…
-
4
votes3
answers693
viewsA: How to know the amount of NA in each variable?
Use sapply to apply its function to each column of the data.frame df v v2 v3 v4 1 1 11 21 a 2 2 NA 22 b 3 NA NA 23 c 4 4 14 24 <NA> 5 NA NA 25 <NA> 6 6 16 26 <NA> 7 7 NA 27 g 8 8…
ranswered Marcos Banik 1,779 -
11
votes2
answers355
viewsA: Negative variance in R? Floating point error propagation
His function was the victim of catastrophic cancellation. This can happen when subtracting two numbers next to and from the same sign, in the case of its function: sum(x2^2) [1] 1e+27 sum(x2)^2 /…
-
12
votes4
answers1519
viewsA: Why is 0.1 + 0.05 not equal to 0.15? What solutions can be used in R?
I could not explain better than Guilherme Bernal why this happens. For this reason, I will limit myself to how to get around the situation within the R. To understand how the R "see" 0.1, 0.05, 0.1…
-
4
votes6
answers31940
viewsA: How to remove a data.frame column in R?
To remove only one column, I prefer the mode used by @carloscinelli dados$x <- NULL head(dados) y z w 1 -0.6264538 0.4094018 0.8936737 2 0.1836433 1.6888733 -1.0472981 3 -0.8356286 1.5865884…
ranswered Marcos Banik 1,779 -
5
votes7
answers8546
viewsA: How to implement a linear regression algorithm?
I don’t know what the algorithm is that function TENDENCIA uses, but if it is only an input variable x and an exit y, the answer to m and b by the least squares method is: (code in R) m <-…
-
0
votes3
answers942
viewsA: Undefined Reference when compiling multiple files
Here it seems to be working. g++ Main.cpp gradebook.cpp
-
3
votes2
answers1093
viewsA: How to compile a *.c file with Clang to signal problems?
the parameter is -Wall I use it in a different order than the one you are using. I think in the end it becomes clearer. clang -Wall nomedoarquivo.c -o nomedoexecutavel clang -Wall *.c -o a clang…