[Solved] How to split the name for student mark list

[ad_1] When you define the new variable, convert results$name to character, not results. Also, use ” ” (a blank space) to split the words, not “” (no space). If you fix that one line, the code seems to work. Change this: new=strsplit(as.character(results),””) to this: new=strsplit(as.character(results$name),” “) 0 [ad_2] solved How to split the name for … Read more

[Solved] How to extract list element names in lapply to rename files

[ad_1] We need to use names instead of name in the OP’s function, use paste0 instead of paste if we don’t need a whitespace between the names and the new string, and return ‘theNamedFile’, then apply the function directly on the ‘mylist’ ReportOp<-function(x){ theNamedFile <- paste0(names(x),”~\\Myfile.pdf”) theNamedFile } ReportOp(mylist) If we apply it using lapply … Read more

[Solved] Syntax error in ggplot Function in R

[ad_1] I think it would be less confusing to revert to a for loop. Try: plotTimeSeries <- list(temp1,temp2,temp3,temp4) for (i in plotTimeSeries) { i$dt <- strptime(i$dt, “%Y-%m-%d %H:%M:%S”) ggplot(i, aes(dt, ambtemp)) + geom_line() + scale_x_datetime(breaks = date_breaks(“2 hour”), labels=date_format(“%H:%M”)) + labs(x=”Time 00.00 ~ 24:00 (2007-09-29)”,y=”Ambient Temperature”, title = (paste(“Node”,i))) } 7 [ad_2] solved Syntax error … Read more

[Solved] Detect the position of a pattern of numbers in a matrix in R [closed]

[ad_1] According to your new rules, may be this helps: data1 <- data #changing some elements to test the code data1[2,8] <-2 data1[4,1] <- 1 ##The code is for the row indx <- which(t(sapply(split(data1 == pattern, row(data1)), { function(x) colSums(sapply(1:(length(x) – 3), function(i) x[seq(i, i + 3)]), na.rm = TRUE) == 4 })), arr.ind = … Read more

[Solved] Find a function to return value based on condition using R

[ad_1] If I understand well, your requirement is to compare sold quantity in month t with the sum of quantity sold in months t-1 and t-2. If so, I can suggest using dplyr package that offer the nice feature of grouping rows and mutating columns in your data frame. resultData <- group_by(data, KId) %>% arrange(sales_month) … Read more

[Solved] Comparing multiple data frames

[ad_1] Here are a couple of ideas. This is what I think your data look like? before <- data.frame(val=c(11330,2721,52438,6124), lab=c(“STAT1″,”STAT2″,”STAT3″,”SUZY”)) after <- data.frame(val=c(17401,3462,0,72), lab=c(“STAT1″,”STAT2″,”STAT3″,”SUZY”)) Combine them into a single data frame with a period variable: combined <- rbind(data.frame(before,period=”before”), data.frame(after,period=”after”)) Reformat to a matrix and plot with (base R) dotchart: library(reshape2) m <- acast(combined,lab~period,value.var=”val”) dotchart(m) Plot … Read more

[Solved] how to erase several characters in a cell? [closed]

[ad_1] What are other patterns your data has? If it’s always “(B)” you can do sub(“\\(B\\)”, “”, df$code) #[1] “1234” “5678” “1234” “5678” “0123” Or if it could be any character do sub(“\\([A-Z]\\)”, “”, df$code) You could also extract only the numbers from Code sub(“.*?(\\d+).*”, “\\1”, df$code) You might want to wrap output of sub … Read more