Posts by Carlos Eduardo Lagosta • 5,497 points
162 posts
-
0
votes1
answer84
viewsA: Encoding problem in a file folder
Try this: arquivoDados <- 'I:\\AGG\\01. DIGEP\\Relatórios Gerenciais\\Edição\\2018-08-17\\listao.csv' listao <- read_csv2(arquivoDados, ...
-
2
votes1
answer476
viewsA: Take a sample without repetition taking into account 2 variables in the R
As your sample data is not large enough for a repeat sampling, I am generating other, simpler, just for demonstration: dados <- data.frame( CNPJ = rep(1:20, each = 3), data = 2015:2017 ) tam…
-
1
votes1
answer372
viewsA: How do I make an NMDS chart?
Check the introduction sticker to the vegan package: vignette("intro-vegan", "vegan") Using the example provided by the package: library(vegan) data(dune) nmds <- metaMDS(dune) plot(nmds, type =…
-
6
votes1
answer309
viewsA: R Delete data frame lines by condition
You can apply any() on each line to hold those that have at least one cell different from the condition: x[apply(x[-1] != 3, 1, any),] Nome I1 I2 I3 I4 1 Laetia 1 1 1 1 3 Lecythis 3 1 1 2 4 Pourouma…
-
4
votes2
answers82
viewsA: Separate subsets of a base in R
fEtapas <- function(x) { linha <- c(grep('\\(ETAPA [0-9]*)$', x[,1]), nrow(x)) etapa <- rep(NA, nrow(x)) for(i in 1:(length(linha)-1)) i -> etapa[linha[i]:linha[i+1]] x$etapa <- etapa…
ranswered Carlos Eduardo Lagosta 5,497 -
4
votes1
answer474
viewsA: How to look for a word within a text in R
@Rui-Arradas has already given the answer in the comments, this is just a elaboration. First, let’s create an example with more phrases. string.vector <- c( "gnoll: Você tem acesso total a esta…
ranswered Carlos Eduardo Lagosta 5,497 -
3
votes1
answer832
viewsA: How to insert a legend on a map in R?
There are several ways to do this. Using ggplot2: library(rgdal) library(ggplot2) library(RColorBrewer) shapeUFs <- readOGR('.', 'UFEBRASIL') # Simulando o resultado do agrupamento por k-means:…
-
4
votes1
answer58
viewsA: Create variables and fill in information from other variables
The function reshape2::dcast does what it needs. You only have to run it once for each semester and put the data together: dados <- data.frame( id = c(rep(9039, 2), rep(8234, 2)), semestre_1 =…
ranswered Carlos Eduardo Lagosta 5,497 -
2
votes1
answer182
viewsA: Turning Chr into a team in R
There are several packages that handle hours format in R. lubridate is probably the most friendly currently. horas <- paste0(1:18,':00') > horas [1] "1:00" "2:00" "3:00" "4:00" "5:00" "6:00"…
ranswered Carlos Eduardo Lagosta 5,497 -
4
votes2
answers1017
viewsA: How to insert a chart caption with two axes y in r?
How the bars use fill and the lines/points use color, you can specify separate scales for each one. Put the name you want in the caption inside the respective aesthetics and colors in the manual…
-
2
votes1
answer649
viewsA: To transform a spreadsheet of presence and absence of species into columns
See if that’s what you need. Since you didn’t post a sample of your data, here’s a fictitious presence and absence matrix to use as an example: matriz.pa <- data.frame( Sitio = LETTERS[1:4],…
ranswered Carlos Eduardo Lagosta 5,497 -
2
votes3
answers226
viewsA: Average temperature in R
You can use data.table. In addition to facilitating group and subset calculations, it has functions to handle date and time. I duplicated your data to contain more than a day: dados <-…