Any data analysts good with R?

The Homebrew Forum

Help Support The Homebrew Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

jceg316

Landlord.
Joined
Sep 8, 2014
Messages
2,811
Reaction score
1,161
I have started using R to analyse data and I'm getting really into it, but I need to do a series of calculations and I'm not sure how. It's possible in excel using a vlookup and I think in R I need to use a for loop.

If someone who's good with R reads this let me know and I'll post the problem, it's a bit long to write out.

Thanks in advance.
 
Ha ive use M n Z and minitab for stats but R is a new one on me tho ive not paid much attention for a decade or 2 ;)
 
Bring the thread back on track, here's the issue:

I work in SEO - looking at my website's rankings in Google and trying to increase them etc. In SEO we use a metric called visibility to work out how good the keywords are which we rank for. For example, we could rank 1st for 1,000 keywords, but if no one is searching for them our visibility is 0 and those keywords are useless. If we rank 3rd for one keyword with 10,000 monthly searches, our visibility will be much higher.

I have ~40,000 keywords ranking somewhere between 1-101 and I need to process them through my own visibility score. This involves multiplying the rank's visibility % by the search volume. I use these %:

Rank - Visibility %
1st - 90%
2nd - 80%
3rd - 70%
4th - 60%
5th - 50%
6th - 40%
7th - 30%
8th - 20%
9th - 10%
10th - 5%
11+ - 0%

So I'm looking to get:

rank% * keyword volume.

For example, let's say I have some keywords:

Keyword - rank - search volume
Keyword A - 1 - 1,000
keyword B - 5 - 30,000
Keyword C -11 - 4,400

I'd need to get 900, 15,000, 0 respectively. Is there a way to do this without having to write out loads of code in an if statement?

Thanks.
 
Bring the thread back on track, here's the issue:

I work in SEO - looking at my website's rankings in Google and trying to increase them etc. In SEO we use a metric called visibility to work out how good the keywords are which we rank for. For example, we could rank 1st for 1,000 keywords, but if no one is searching for them our visibility is 0 and those keywords are useless. If we rank 3rd for one keyword with 10,000 monthly searches, our visibility will be much higher.

I have ~40,000 keywords ranking somewhere between 1-101 and I need to process them through my own visibility score. This involves multiplying the rank's visibility % by the search volume. I use these %:

Rank - Visibility %
1st - 90%
2nd - 80%
3rd - 70%
4th - 60%
5th - 50%
6th - 40%
7th - 30%
8th - 20%
9th - 10%
10th - 5%
11+ - 0%

So I'm looking to get:

rank% * keyword volume.

For example, let's say I have some keywords:

Keyword - rank - search volume
Keyword A - 1 - 1,000
keyword B - 5 - 30,000
Keyword C -11 - 4,400

I'd need to get 900, 15,000, 0 respectively. Is there a way to do this without having to write out loads of code in an if statement?

Thanks.

I don't know R, but it sounds like you need a loop and a switch statement
 
I don't know R, but it sounds like you need a loop and a switch statement

Yeah I've got that far, I know I need to do something with a for loop but not sure what. I didn't bring it up in case a for loop isn't what I'm after and I send people down the wrong path.
 
Bring the thread back on track, here's the issue:

I work in SEO - looking at my website's rankings in Google and trying to increase them etc. In SEO we use a metric called visibility to work out how good the keywords are which we rank for. For example, we could rank 1st for 1,000 keywords, but if no one is searching for them our visibility is 0 and those keywords are useless. If we rank 3rd for one keyword with 10,000 monthly searches, our visibility will be much higher.

I have ~40,000 keywords ranking somewhere between 1-101 and I need to process them through my own visibility score. This involves multiplying the rank's visibility % by the search volume. I use these %:

Rank - Visibility %
1st - 90%
2nd - 80%
3rd - 70%
4th - 60%
5th - 50%
6th - 40%
7th - 30%
8th - 20%
9th - 10%
10th - 5%
11+ - 0%

So I'm looking to get:

rank% * keyword volume.

For example, let's say I have some keywords:

Keyword - rank - search volume
Keyword A - 1 - 1,000
keyword B - 5 - 30,000
Keyword C -11 - 4,400

I'd need to get 900, 15,000, 0 respectively. Is there a way to do this without having to write out loads of code in an if statement?

Thanks.

Here you go:
Code:
keywords <- c("A","B","C","D","E","F","G","H","I","J")
visibilities <- c(95,90,80,70,55,45,35,15,5,0)
volumes <- c(1000,200,40000,25000,1250,6000,2000,2000,300,100) 
d <- data.frame(keywords,visibilities,volumes,visibilities*volumes)
d[order(-d[,4]), ]

This gives you the following output, showing the keyword, visibilities, volumes, and the product of volume and visibility, all ordered by the latter:

Code:
   keywords visibilities volumes visibilities...volumes
3         C           80   40000                3200000
4         D           70   25000                1750000
6         F           45    6000                 270000
1         A           95    1000                  95000
7         G           35    2000                  70000
5         E           55    1250                  68750
8         H           15    2000                  30000
2         B           90     200                  18000
9         I            5     300                   1500
10        J            0     100                      0



EDIT: I don't know how you are reading the data into R, but the above could be modified pretty easily to put the visibility in the rank->visibility mapping into the data frame.
 
Here you go:
Code:
keywords <- c("A","B","C","D","E","F","G","H","I","J")
visibilities <- c(95,90,80,70,55,45,35,15,5,0)
volumes <- c(1000,200,40000,25000,1250,6000,2000,2000,300,100) 
d <- data.frame(keywords,visibilities,volumes,visibilities*volumes)
d[order(-d[,4]), ]

This gives you the following output, showing the keyword, visibilities, volumes, and the product of volume and visibility, all ordered by the latter:

Code:
   keywords visibilities volumes visibilities...volumes
3         C           80   40000                3200000
4         D           70   25000                1750000
6         F           45    6000                 270000
1         A           95    1000                  95000
7         G           35    2000                  70000
5         E           55    1250                  68750
8         H           15    2000                  30000
2         B           90     200                  18000
9         I            5     300                   1500
10        J            0     100                      0



EDIT: I don't know how you are reading the data into R, but the above could be modified pretty easily to put the visibility in the rank->visibility mapping into the data frame.

Thanks for your reply! I feel this is almost there, it's a step is missing - matching up the keyword's rank to the visibility %. Is there a way of creating two vectors, one with rank, another with visibility score and creating an "index" with that?

I do appreciate the help, still very new to R and trying to climb up the steep learning curve!
 
Here you go:
Code:
keywords <- c("A","B","C","D","E","F","G","H","I","J")
visibilities <- c(95,90,80,70,55,45,35,15,5,0)
volumes <- c(1000,200,40000,25000,1250,6000,2000,2000,300,100) 
d <- data.frame(keywords,visibilities,volumes,visibilities*volumes)
d[order(-d[,4]), ]

This gives you the following output, showing the keyword, visibilities, volumes, and the product of volume and visibility, all ordered by the latter:

Code:
   keywords visibilities volumes visibilities...volumes
3         C           80   40000                3200000
4         D           70   25000                1750000
6         F           45    6000                 270000
1         A           95    1000                  95000
7         G           35    2000                  70000
5         E           55    1250                  68750
8         H           15    2000                  30000
2         B           90     200                  18000
9         I            5     300                   1500
10        J            0     100                      0

I'm sorry i opened my mouth. What is this witchcraft?

Think i'll stick with my object orientation
 
Thanks for your reply! I feel this is almost there, it's a step is missing - matching up the keyword's rank to the visibility %. Is there a way of creating two vectors, one with rank, another with visibility score and creating an "index" with that?

I do appreciate the help, still very new to R and trying to climb up the steep learning curve!

Here:
Code:
keywords <- c("A","B","C","D","E","F","G","H","I","J")
ranks <- c(3,1,5,7,2,8,2,4,9,2)
rank_to_visibility <- c(95,90,80,70,55,45,35,15,0)
visibilities <- rank_to_visibility[ranks]
volumes <- c(1000,200,40000,25000,1250,6000,2000,2000,300,100)
d <- data.frame(keywords,visibilities,volumes,visibilities*volumes)
d[order(-d[,4]), ]

The rank_to_visibility converts the rank into the visibility score. In this toy example there are only 9 ranks, thought I understand you will have 101. Then, we create a new vector, visibilities, which has the same length as the number of keywords, and contains the visibility instead of the rank. The rest is the same:

Code:
> d[order(-d[,4]), ]
   keywords visibilities volumes visibilities...volumes
3         C           55   40000                2200000
4         D           35   25000                 875000
7         G           90    2000                 180000
8         H           70    2000                 140000
5         E           90    1250                 112500
6         F           15    6000                  90000
1         A           80    1000                  80000
2         B           95     200                  19000
10        J           90     100                   9000
9         I            0     300                      0
 

Latest posts

Back
Top