0

I have the data available in the below format & instead of adding the nos. manually, I want to read them directly from the csv file. Please check the **"Total Clicks" ** and **"Version # Opens" ** section. Thanks in advance

Data I have in .csv format:

Total Clicks                
Section   Version A  Version B  Version C   Version D  
Section1    1,999   2,116              2,307    2,568
Section2    3,450   1,781              3,416    1,399
Section3    1,773     915              1,744      644
Section4        0   2,255                  0    1,432
Section5      588     573                721      235
Main email  7,222   7,067              7,467    6,043
Total email 7,810   7,640              8,188    6,278

Version # Opens
A    9,073
B    9,150
C    9,215
D    9,153

Currently I am assigning the data manually in the below format:

S1_Click_A=1,999 ####(section 1, email A)
S1_Click_B=2,116 ## (section 1, email B)
S1_Click_C=2,307
S1_Click_D=2,568
S2_Click_A=3,450 
S2_Click_B=1,781 
.
.
.
S5_Click_C=721 
S5_Click_D=235
MainBody_Click_A=7,222
MainBody_Click_B=7,067
.
.
TotalEmail_Click_C=8,188
TotalEmail_Click_D=6,278

I expect a code which helps to pick the data directly from the file instead of doing this manually.

camille
  • 16,432
  • 18
  • 38
  • 60
sahay
  • 27
  • 5
  • 1
    Have you tried the `read.csv` function in R? – sumshyftw May 17 '19 at 17:56
  • yes! but I want to read the data in the above format. I mean reading the section1 version A data i.e 1,999 and assigning the same to S1_Click_A=1,999 similarly for others. – sahay May 17 '19 at 18:01
  • You might have trouble with the fact that you're reading a csv file where values have commas in them. What are you doing in order to read the csv file? Also, do you have things setup so 1,999 is treated as a decimal value? Because otherwise, `S1_Click_A=1,999` is not syntax that will work – camille May 17 '19 at 19:01
  • Are you having issues reading the file, or do you want to assign each variable in your dataframe to an individual variable. If the latter, than you probably want `assign`, in which case you should read why `assign` [isn't a great idea](https://stackoverflow.com/questions/17559390/why-is-using-assign-bad). –  May 17 '19 at 19:04
  • There is no issue with the commas, I can replace them. The file I have is in excel and yes @gersht you are right I want to assign each variable in dataframe to an individual variable. So For exa: S1_Click_A= 1999 S2_Click_B= 2116 – sahay May 17 '19 at 19:09
  • adding to the above point, I need to calculate P- values for each combination Link to the previous question: https://stackoverflow.com/questions/56181335/is-there-anyway-to-automate-manualr-code-for-calculation-of-p-values – sahay May 17 '19 at 19:16

1 Answers1

0

I would say that you could do something like this:

library(tidyverse)
wide_file <- read_csv("you_file.csv")

# Gather to make it long

long_file <- wide_file %>%
    gather(version, value, -Section)

# Now make your new column using unite (basically pastes columns together)

long_file_2 <- long_file %>%
    unite("new_col", id:version, sep = "_)

That should give you the data format that you have specified

MDEWITT
  • 2,338
  • 2
  • 12
  • 23