[Solved] Creating a ternary plot

I started with library(ggtern) ggtern(df,aes(GRAVEL,SAND,MUD))+geom_point() Adding fill=Root within the aes() function and shape=21 outside would colour in the points according to the value of some other variable, but it only makes most sense to colour the points if you have a separate variable in your data set which could determine the colour — your example … Read more

[Solved] how we can filter data in dataframe in R [closed]

# Filter dat.filtered <- subset(dat, f2 > 0) # Convert to time-series library(xts); xts.sample <- xts(dat.filtered$f2, order.by = as.Date(dat.filtered$f1, “%d/%m/%Y”)) Sample data dat <- read.table(text = ” f1 f2 1 11/1/16 0 2 12/1/16 0 3 11/2/16 56.25 4 12/2/16 0 5 11/3/16 56.25 6 12/3/16 0 7 11/4/16 111 8 12/4/16 0 9 11/5/16 … Read more

[Solved] to get data.frame from xts form data [closed]

Here’s a crack at what you want. I think your problem starts with how SDB is stored. To see what an object looks like use str. I don’t know what an xts object is but using str helps me determine how to pull out the pieces I want. str(SDB) > str(SDB) An ‘xts’ object from … Read more

[Solved] How to add a legend to ggplot when aes are constant for stat_smooth

You can still use aes in each stat_smooth including only the desired color. This will add legends to the plot. Then you can use scale_color_identity to match and rename the colors ggplot(mtcars, aes(x=wt, y = mpg, col=”green”)) + geom_point(col=”blue”) + stat_smooth(method=’loess’,linetype=”dashed”, aes(color = “red”), span=0.1) + stat_smooth(method=’loess’,linetype=”dashed”, aes(color = “orange”), span=0.25) + stat_smooth(method=’loess’,linetype=”dashed”, aes(color = … Read more

[Solved] extracting exact number of rows from a list [closed]

A bit untidy, but does the job: d <- data.frame(a=a[-(1:2)], diff=diff(a, 2)) d$br <- 0 for (i in 1:nrow(d)) { if (i==1 & d$diff[1]==2) { d$br[1] <- 1 } else if (i==2 & d$diff[2]==2 & d$br[1]!=1) { d$br[2] <- 1 } if (d$diff[i]==2 & !any(sum(d$br[c(i-1, i-2)])>0)) d$br[i] <- 1 } t(sapply(d$a[d$br==1], function(x) (x-2):x)) # [,1] … Read more

[Solved] Replace Values in a column wiht NA if values from another column are not 1 [closed]

Try library(sp) S@coords[,’roadtype’][S@coords[,’jointcount’]!=1] <- NA S # SpatialPoints: # jointcount roadtype #[1,] 1 3 #[2,] 4 NA #[3,] 3 NA #[4,] 1 1 #[5,] 1 4 data jointcount = c(1,4,3,1,1) roadtype = c(3,2,5,1,4) S <- SpatialPoints(data.frame(jointcount,roadtype)) solved Replace Values in a column wiht NA if values from another column are not 1 [closed]

[Solved] Find duplicate registers in R [closed]

Assuming the “df” dataframe has the relevant variables under the names “channel” and “email”, then: To get the number of unique channel-email pairs: dim(unique(df[c(“channel”, “email”)]))[1] To get the sum of all channel-email observations: sum(table(df$channel, df$email)) To get the number of duplicates, simply subtract the former from the later: sum(table(df$channel, df$email)) – dim(unique(df[c(“channel”, “email”)]))[1] 0 solved … Read more

[Solved] more basic R commands than plot [closed]

#margins parameters mar_save <- par(“mar”) par(mar=c(2, 2.3, 0, 0)) #plot windows and initialisation xmin <- -1 xmax <- 11 ymin <- 0 ymax <- 10 plot(x = c(xmin,xmax), y = c(ymin,ymax), xlim = c(xmin,xmax), ylim = c(ymin,ymax), type = “n”, xaxs = “i”, xaxt = “n”, yaxs = “i”, yaxt = “n”) # axes labels … Read more

[Solved] Subsetting multiple vectors based on a specific condition

Well, I am not sure if Tail and Class are part of the same dataframe or are two seperate vectors. If they are two seperate vectors, maybe you can merge the two vectors in a dataframe df <- data.frame(Tail = as.character(Tail), Class = as.character(Class)) and then with dplyr you can try, library(dplyr) df %>% group_by(Tail) … Read more

[Solved] To get the most frequent levels in a data frame

You can do something like this with dplyr set.seed(43) df<-data.frame(location=sample(LETTERS[1:3],20,replace=TRUE), site=sample(c(“bang”,”mys”,”hubl”,”dar”),20,replace=TRUE)) library(dplyr) df%>%group_by(location,site)%>%summarize(Count=n())%>%arrange(desc(Count))%>%slice(1)%>%ungroup()%>%select(location,site) 3 solved To get the most frequent levels in a data frame

[Solved] Is there an efficient method to check for 8 successive elements that are not NA (i.e. is.na()==FALSE) in each column of a large dataset?

The following code does what the question asks for. The function that does all the work is append_one. It Creates a vector Y repeating the prefix length(x) times. Gets the runs of vector y. Cleans the runs’ values to the empty string “” if the runs’ lengths are less than N. Reverses the run-length encoding. … Read more