connect to tableau
# Load required librarylibrary(readxl)
# Read data from Excel filedata <- read_excel("C:\\Users\\NATHDWAR\\Desktop\\1.xlsx")
# Function to extract values from column "C"extract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[start_pos], start = nchar(start_word[i]) + 1, stop = nchar(data$C[start_pos]) - nchar(stop_word[i]) - 1)}return(result)}
# Example usagestart_words <- data$Astop_words <- data$Bvalues <- extract_values(start_words, stop_words, data)print(values)
# Load required librarieslibrary(readxl)library(dplyr)
# Read data from Excel filesfile1 <- read_excel("path_to_file1.xlsx")file2 <- read_excel("path_to_file2.xlsx")
# Perform the join based on a common constraintjoined_data <- inner_join(file1, file2, by = "common_column_name")
# common_column_name should be replaced with the actual column name that is common between the two files
# View the joined dataprint(joined_data)
# Read data from Excel filedata <- read_excel("path_to_your_excel_file.xlsx")
# Function to extract values from column "C"extract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[start_pos], start = nchar(start_word[i]) + 1, stop = nchar(data$C[start_pos]) - nchar(stop_word[i]) - 2)} else if (start_word[i] == "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[stop_pos], start = 1, stop = nchar(data$C[stop_pos]) - nchar(stop_word[i]) - 2)} else if (stop_word[i] == "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(data$C[start_pos], start = nchar(start_word[i]) + 1, stop = nchar(data$C[start_pos]))}}return(result)}
# Function to extract values from column "C"extract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[start_pos], start = nchar(start_word[i]) + 1, stop = nchar(data$C[start_pos]) - nchar(stop_word[i]) - 2)} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[stop_pos], start = 1, stop = nchar(data$C[stop_pos]) - nchar(stop_word[i]) - 2)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(data$C[start_pos], start = nchar(start_word[i]) + 1, stop = nchar(data$C[start_pos]))}}return(result)}
# Function to extract values from column "C"extract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[start_pos], start = nchar(as.character(start_word[i])) + 1, stop = nchar(data$C[start_pos]) - nchar(as.character(stop_word[i])) - 2)} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(data$C[stop_pos], start = 1, stop = nchar(data$C[stop_pos]) - 1)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(data$C[start_pos], start = nchar(as.character(start_word[i])) + 1, stop = nchar(data$C[start_pos]))}}return(result)}
now1
# Function to extract values from column "C"extract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])) - nchar(as.character(stop_word[i])) - 2)} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(as.character(data$C[stop_pos]), start = 1, stop = nchar(as.character(data$C[stop_pos])) - 1)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])))}}return(result)}
# Example usagestart_words <- data$Astop_words <- data$Bvalues <- extract_values(start_words, stop_words, data)print(values)now 2
# Load required librarieslibrary(readxl)library(openxlsx)
# Function to extract values from column "C" and include all original columnsextract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])) - nchar(as.character(stop_word[i])) - 2)} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(as.character(data$C[stop_pos]), start = 1, stop = nchar(as.character(data$C[stop_pos])) - 1)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])))}}# Create a data frame with all original columns and the extracted valuesresult_df <- cbind(data, Extracted_Values = result)return(result_df)}
# Example usagestart_words <- data$Astop_words <- data$Bvalues <- extract_values(start_words, stop_words, data)
# Write data to a new Excel filewrite.xlsx(values, "output_file.xlsx")
# Function to extract values from column "C" and include all original columnsextract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- which(data$A == start_word[i])stop_pos <- which(data$B == stop_word[i])if (length(start_pos) > 0 & length(stop_pos) > 0 & stop_pos > start_pos) {result[i] <- substr(data$C[start_pos], start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])) - nchar(as.character(stop_word[i])) - 2)} else {result[i] <- NA}} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- which(data$B == stop_word[i])result[i] <- substr(as.character(data$C[stop_pos]), start = 1, stop = nchar(as.character(data$C[stop_pos])) - 1)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- which(data$A == start_word[i])result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])))}}# Create a data frame with all original columns and the extracted valuesresult_df <- cbind(data, Extracted_Values = result)return(result_df)}
now 3
# Function to extract values from column "C" and include all original columnsextract_values <- function(start_word, stop_word, data) {result <- character(length(start_word))for (i in seq_along(start_word)) {if (!is.na(start_word[i]) & !is.na(stop_word[i]) & start_word[i] != "" & stop_word[i] != "") {start_pos <- grep(start_word[i], data$A)stop_pos <- grep(stop_word[i], data$B)if (length(start_pos) > 0 & length(stop_pos) > 0 & stop_pos > start_pos) {result[i] <- substr(data$C[start_pos], start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])) - nchar(as.character(stop_word[i])) - 2)} else {result[i] <- NA}} else if (is.na(start_word[i]) & !is.na(stop_word[i]) & stop_word[i] != "") {# Get all words before stop wordstop_pos <- grep(stop_word[i], data$B)result[i] <- substr(as.character(data$C[stop_pos]), start = 1, stop = nchar(as.character(data$C[stop_pos])) - 1)} else if (!is.na(start_word[i]) & is.na(stop_word[i]) & start_word[i] != "") {# Get all words after start wordstart_pos <- grep(start_word[i], data$A)result[i] <- substr(as.character(data$C[start_pos]), start = nchar(as.character(start_word[i])) + 1, stop = nchar(as.character(data$C[start_pos])))}}# Create a data frame with all original columns and the extracted valuesresult_df <- cbind(data, Extracted_Values = result)return(result_df)}