[Solved] Very new in R, subsetting columns

#columns 4 to the last one myselec<-mydata[ 1, 4 : ncol(mydata)] #put the columns you want to keep in a vector columnsIWantToKeep <- c(4, 5, 6, 10, 12) #subset your DFusing this vector myselec<-mydata[1, columnsIWantToKeep] The same applies to rows… myselec<-mydata[ 4:nrow(mydata),] #get from row 4 to the end myselec<-mydata[ c(1,3,5,7),] #get rows 1,3,5,7 You … Read more

[Solved] vector of characters into expression [closed]

I’m not sure there is enough information in your question for me to give you a specific answer, but here’s a start… You can extract the variable names from a data.frame called df with: names_vec <- names(df) You can get the desired pattern of variable names with plus signs between them with: string_1 <- paste(names_vec, … Read more

[Solved] Subset and filter not giving proper answer

Since your column C1 is numeric, you should not use quotes. Try this: subset(KL, C1 > 300) ID C1 1 A 597.69 3 C 601.30 4 D 4052.60 15 O 354.12 But note that you should use caution with subset() – this will not always do what you think it does. It’s better to use … Read more

[Solved] Convert text file to matrix [closed]

I will try to guess what is asked. Assuming that your data frame is named df, you can convert each column to matrix and put it in list using lapply(). For example, I converted to matrix with two columns. seq_len(ncol(df) will make sequence of numbers from 1 to number of columns, so conversion will iterate … Read more

[Solved] Convert text file to matrix [closed]

Introduction This post provides a solution to the problem of converting a text file into a matrix. The solution involves using a combination of programming languages such as Python, R, and MATLAB to read the text file and then convert it into a matrix. The post also provides a step-by-step guide on how to do … Read more

[Solved] Plotting two scatter plots and regression lines with error bars on same plot using ggplot2 [closed]

ggplot2 is my favourite R package, so here is how I would solve this: df = data.frame(difficulty = 2 + (runif(200) * 6), ID = rep(c(“point”, “bubble”), each = 100)) df$movement = rep(c(1.2, 1.4), each = 100) * df$difficulty + (runif(200) / 5) library(ggplot2) theme_set(theme_bw()) ggplot(df, aes(x = difficulty, y = movement, color = ID, … Read more

[Solved] Extracting Data from a list- find the highest value

I’m assuming IATA is the ticket agent variable: df = data.frame(IATA=c(3300, 3300, 3300, 3300, 3301, 3301, 3302, 3303, 3303)) table(df$IATA) # 3300 3301 3302 3303 # 4 2 1 2 As you can see, table gives the frequency of ticket sales by each ticket agent. names(which.max(table(df$IATA))) # [1] “3300” If there are ties and you … Read more

[Solved] Remove selected columns in R dataframe [duplicate]

###Use subset command:### dataframename <- subset(dataframename, select = -c(col1,col4) ) ###One more approach is you can use list(NULL) to the dataframe:### dataframename[,c(“col1″,”col4”)] <- list(NULL) solved Remove selected columns in R dataframe [duplicate]

[Solved] Why do we use group = group in ggplot2 plots in R?

The example that you give is for plotting maps, usually starting from a shapefile. In that case the data contains a column named group which is used by geom_polygon to ensure that boundaries and shapes are connected correctly. If the column were named something else, e.g. xxx, then you’d use group = xxx. This question … Read more