Hi. As the title says, I resolved the following error. What I tried There were two. When you try these, you will need to take full responsibility for your action. Backup is important. The first one is a GPU driver update. Valkan will be installed along with the driver update, so I tried this method first. However, changing the driver sometimes causes instability, so I recommend checking the current version from the device manager. The second one is installing the latest version of Valkan Runtime. I referred to this nice Japanese article. https://emulog.net/ps3-emulator-rpcs3-cant-run-missing-vulkan-1-dll/ In my environment, the problem was resolved. However, my GPU was too old to play :( I hope these information helps you. Bye.
Hi. Good morning / afternoon / evening. I’m ponpokorin (@ponpokorin_24).
I think you learned the basic usage of R last time (Part 2). So, this time, let's find out that you can try various things based on the previous knowledge.
This time, of course, I will write on the premise that R is installed.
If you came to see this article first, please check Part 1 and Part 2 as well.
Why "every 25 minutes" is because there is my recommended concentration method called Pomodoro Technique. Simply put, set a 25-minute timer, and during that time focus on the task at hand. And when the timer rings, take a break for 5 minutes. Then, concentrate for 25 minutes again… You repeat this process to finish the tasks you are doing.
If you're saying, "It's hard to concentrate for me" please read this article of mine. I think you can read it in about 5 minutes.
Let's enjoy programming!
So, let's try the package. First, let's write the following command to R Console. Also, because it uses a new command, you may think "I do not understand the meaning", but please copy it for now.
fn <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 10
ans[2] <- a - b - 6
return(ans)
}
nleqslv(c(1, 1), fn)
How about that?
Error with nleqslv (c (1, 1), fn):
Could not find function "nleqslv"
I think you got an error like the one above. So, type the following command. This is the command to install a package.
install.packages("nleqslv")
When you enter the command, the following screen will be displayed. You can choose a location you like, but basically you should choose a location closer to your home to download faster.
After a moment, the screen will look like this.
Now, type the following command.
library(nleqslv)
nleqslv(c(1, 1), fn)
How is it? You can use "nleqslv" which you couldn’t use before!
At this point you have obtained additional commands. Please note that you once installed package, in this case "nleqslv", it was downloaded and installed in your computer, so you don't need to type “install.packages("nleqslv")” next time.
So, before we look at the meaning of each of the commands we've used, let's first talk about what we were doing.
a + b = 10
a - b = 6
Ans. a=8, b=2
It's easy, don't you? This was solved using a computer. Humans can easily solve such simultaneous equations, but it becomes troublesome when the number of equations increases and the variables increase such as a, b, c, d, ...
In such cases, a computer can calculate quickly and accurately.
(If you are reading on a smartphone and the sentence is difficult to read, please try the screen sideways.)
# install.packages("nleqslv") # Run only when first installation
library(nleqslv)
fn <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 10
ans[2] <- a - b - 6
return(ans)
}
nleqslv(c(1, 1), fn)
Let's check in order from the top.
The first is "comment out by #". This is a previous review. By doing so, from the second time, "install.packages" will not run even if you Ctrl + A and Ctrl + R. You can copy and paste it into the editor, and then, save it.
Next, let's talk about "("nleqslv")" in "install.packages ("nleqslv")". Characters enclosed in double quotes are recognized by the computer as strings. The command "install.packages" is based on the assumption that you put the string in parentheses. So, I enclose nleqslv in double quotes.
Note: What is inside the parentheses of a command is called an Argument.
Now let's talk about each command. It may be a bit difficult, so it's okay to take a break once.
“Somewhat okay ...” but it’s enough. The important thing this time is to know about the package. Let's get used to it in the future. Next, I will write about “nleqslv”, but it is a bit difficult too, so it's okay if you can use “nleqslv” by copying usage (how to write commands)
In the above example, we put “c(1, 1)” in A. But, if we put “c(2, 1)” or “c(3,10)”, we can get the answer properly too. Please give it a try.
As for the format of B, I think you understand faster by typing a couple of examples rather than being explained in words, so I'll put a couple examples at the end of this article. If you want to master "nleqslv", please check it out.
As I mentioned before, one of the goals of writing a program is to analyze the data. However, such data is usually stored as an Excel file, for example, a file like sample.xlsx, or a csv file (comma-separated text data).
Sometimes we want to read and process such files. At that time, the working directory becomes important. Let's download the csv file.
財務省貿易統計 - 輸出入額の推移(地域(国)別・主要商品別)
https://www.customs.go.jp/toukei/suii/html/time.htm
There is also an English version page, but let's use a Japanese page!
When you visit the page above, you can see “世界 年別”
If you are using Microsoft Edge, right click and select "Save Target As",
If you use Google Chrome, left-click to change the screen, right-click and click "Save As"
(The words may be different because I use Japanese environment m(_ _)mぺこり)
If you save it as it is, it will be named “d41ca.csv” (as of March 5, 2020. It may change).
Now, you are ready.
read.csv("C:/R_data/d41ca.csv")
Your computer loaded it properly!
Now try the following command
setwd("C:/R_data")
read.csv("d41ca.csv")
Did you notice the difference? Yes, we are doing the same thing, but the information passed to "read.csv" is shortened from "C: /R_data/d41ca.csv" to "d41ca.csv".
This is because the working directory was specified with the command "setwd" (set working directory). Open the editor, write your favorite command, and press the save button (you can also save it with Ctrl + S). You will see a screen like this, then please pay attention to the save destination!
It is going to be saved in C (D in my case): / R_data.
By specifying the working directory like this, you can save the trouble of clicking many times for selecting the save destination, and you can use a shorter sentence when reading the file.
In the current example, the amount of writing has increased, but when you want to read some files, for example,
read.csv("C:/aaa/bbb/ccc/aiueo.csv")
read.csv("C:/aaa/bbb/ccc/kakikukeko.csv")
read.csv("C:/aaa/bbb/ccc/sasisuseso.csv")
read.csv("C:/aaa/bbb/ccc/tatituteto.csv")
this become
setwd("C:/aaa/bbb/ccc")
read.csv("aiueo.csv")
read.csv("kakikukeko.csv")
read.csv("sasisuseso.csv")
read.csv("tatituteto.csv")
It's organized and easy to see.
Now do you understand the usefulness of working directory?
After a short break, next is the last content!
mode(c(1,1))
mode("program")
I think the above command returned "numeric", and the lower command returned "character". Here, "mode" is a command that returns the type of the object. An object is created by a command, and the result (object) output by "read.csv" above also has a type. Let's check it out.
mode(read.csv("d41ca.csv"))
I think the list has returned. Thus, each object has a type. Why have a type? You can get it by typing the following command.
1+2
"1"+"2"
mode(1)
mode("1")
I think there was an error in the second line. Since + can only be calculated between "numeric", an error is immediately generated. Because of the type, the computer is not confused even if "character" etc. is mistakenly included in the calculation formula.
Sometimes, however, it is difficult to achieve the desired result due to the type. I wrote a command example below. This can be ignored.
# Goal: I want to divide 1979 by 10 (1979 is fourth element in column 1 of data)
data <- read.csv("d41ca.csv")
mode(data) # Basically, use [[]] to access list
data[[1]][4] # extract fourth element in the first (first column) of data
data[4,1] # You can also extract data by writing 4 rows and 1 column of data, you can extract the entire first column with data[, 1]
# use data[4,1] because it's easier
mode(data[4,1]) # Numeric, so it’s likely to divide by 10
data[4,1]/10 # Can’t divide… In this case, it would be factor
as.numeric(data[4,1]) # “as.numeric” is a command to change the type to numeric. But it will be 2
as.numeric(as.character(data[4,1])) # yippee!
as.numeric(as.character(data[4,1])) / 10 # GOAL accomplished!
This is the end of the Part 3.
if you have a command you need or interesting in this article, write a comment in the editor and save it. If you save the file with a descriptive name, it will be easier to find later.
After the important save is completed, return to the screen of R, press "X" on the upper right, select "No" in "Save workspace?", And R will be finished safely. Good work!
If you like it, please feel free to advertise on social media, etc. ... Since I wrote it, I really want to see as many people as possible lol.
Thank you for your reading! See you again!
The first one is
a + b + c = 10
a + b - c = 8
a - b - c = - 4
The second one is
a + b = 1
a² + b² = 13
Let’s use “nleqslv”!
library(nleqslv)
fn2 <- function(x) {
a <- x[1]
b <- x[2]
c <- x[3]
ans <- c()
ans[1] <- a + b + c - 10
ans[2] <- a + b - c - 8
ans[3] <- a - b - c + 4
return(ans)
}
nleqslv(c(1, 1, 1), fn2)
fn3 <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 1
ans[2] <- a^2 + b^2 - 13
return(ans)
}
nleqslv(c(1, -1), fn3) # c(1, 1) don’t work
I think you learned the basic usage of R last time (Part 2). So, this time, let's find out that you can try various things based on the previous knowledge.
This time, of course, I will write on the premise that R is installed.
If you came to see this article first, please check Part 1 and Part 2 as well.
Table of Contents
- Let’s use packages
- Let's set the working directory
- Experiment with data types
Why "every 25 minutes" is because there is my recommended concentration method called Pomodoro Technique. Simply put, set a 25-minute timer, and during that time focus on the task at hand. And when the timer rings, take a break for 5 minutes. Then, concentrate for 25 minutes again… You repeat this process to finish the tasks you are doing.
If you're saying, "It's hard to concentrate for me" please read this article of mine. I think you can read it in about 5 minutes.
Let's enjoy programming!
Let’s use packages
A package is like a collection of commands that cannot be used by default. If you compare it in a game, it is like an additional DLC or MOD. The MOD will be the closest because the package can be installed for free.So, let's try the package. First, let's write the following command to R Console. Also, because it uses a new command, you may think "I do not understand the meaning", but please copy it for now.
fn <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 10
ans[2] <- a - b - 6
return(ans)
}
nleqslv(c(1, 1), fn)
How about that?
Error with nleqslv (c (1, 1), fn):
Could not find function "nleqslv"
I think you got an error like the one above. So, type the following command. This is the command to install a package.
install.packages("nleqslv")
When you enter the command, the following screen will be displayed. You can choose a location you like, but basically you should choose a location closer to your home to download faster.
I live in Japan, so I chose "Japan" |
After a moment, the screen will look like this.
Now, type the following command.
library(nleqslv)
nleqslv(c(1, 1), fn)
How is it? You can use "nleqslv" which you couldn’t use before!
I think the result looks like this. I'll explain this command a little later. |
At this point you have obtained additional commands. Please note that you once installed package, in this case "nleqslv", it was downloaded and installed in your computer, so you don't need to type “install.packages("nleqslv")” next time.
So, before we look at the meaning of each of the commands we've used, let's first talk about what we were doing.
What I did with a computer is…
What we did above was “solve the simultaneous equations”! Although it was difficult to understand with the commands, we only solved the following simple simultaneous equations.a + b = 10
a - b = 6
Ans. a=8, b=2
It's easy, don't you? This was solved using a computer. Humans can easily solve such simultaneous equations, but it becomes troublesome when the number of equations increases and the variables increase such as a, b, c, d, ...
In such cases, a computer can calculate quickly and accurately.
Command description
Now that you know what you did, let's look at the command again.(If you are reading on a smartphone and the sentence is difficult to read, please try the screen sideways.)
# install.packages("nleqslv") # Run only when first installation
library(nleqslv)
fn <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 10
ans[2] <- a - b - 6
return(ans)
}
nleqslv(c(1, 1), fn)
Let's check in order from the top.
The first is "comment out by #". This is a previous review. By doing so, from the second time, "install.packages" will not run even if you Ctrl + A and Ctrl + R. You can copy and paste it into the editor, and then, save it.
Next, let's talk about "("nleqslv")" in "install.packages ("nleqslv")". Characters enclosed in double quotes are recognized by the computer as strings. The command "install.packages" is based on the assumption that you put the string in parentheses. So, I enclose nleqslv in double quotes.
Note: What is inside the parentheses of a command is called an Argument.
Now let's talk about each command. It may be a bit difficult, so it's okay to take a break once.
library
You can't use the new command just by installing the package. You need to tell your computer that “I will use this package” to use it. For this purpose, command "library" exists. "library" takes an ordinary statement, not a string, as its argument.function
Command for defining a function. Roughly speaking, a function in programming do " perform various calculations and return results using parameters." Write the part "perform various calculations and return results" in {}.“Somewhat okay ...” but it’s enough. The important thing this time is to know about the package. Let's get used to it in the future. Next, I will write about “nleqslv”, but it is a bit difficult too, so it's okay if you can use “nleqslv” by copying usage (how to write commands)
nleqslv
This command is for solving simultaneous equations of multiple variables. The usage is “nleqslv(A, B)”, where A is the initial value and B is the equation you want to solve written in a certain format. (In most cases) Anything is OK for A unless it is far from the solution.In the above example, we put “c(1, 1)” in A. But, if we put “c(2, 1)” or “c(3,10)”, we can get the answer properly too. Please give it a try.
As for the format of B, I think you understand faster by typing a couple of examples rather than being explained in words, so I'll put a couple examples at the end of this article. If you want to master "nleqslv", please check it out.
Let's set the working directory
Now that you know how to use the package, let's move away from the console and learn about the working directory. Of course, while moving your hands. Just reading will make you sleepy, don’t you?As I mentioned before, one of the goals of writing a program is to analyze the data. However, such data is usually stored as an Excel file, for example, a file like sample.xlsx, or a csv file (comma-separated text data).
Sometimes we want to read and process such files. At that time, the working directory becomes important. Let's download the csv file.
Download statistical data
Perhaps you're worried about downloading unreliable files, so let's use statistics from the Japanese Ministry of Finance (I'm Japanese).財務省貿易統計 - 輸出入額の推移(地域(国)別・主要商品別)
https://www.customs.go.jp/toukei/suii/html/time.htm
There is also an English version page, but let's use a Japanese page!
When you visit the page above, you can see “世界 年別”
If you are using Microsoft Edge, right click and select "Save Target As",
If you use Google Chrome, left-click to change the screen, right-click and click "Save As"
(The words may be different because I use Japanese environment m(_ _)mぺこり)
If you save it as it is, it will be named “d41ca.csv” (as of March 5, 2020. It may change).
Create folder
Next, create a folder named “R_data” on the C drive (or D drive if you create a D drive, etc. beforehand with a partition tool. In that case, change C to D with the following command). Move or copy the downloaded “d41ca.csv” into that folder. If you do not know how to create a folder, you can find out immediately by searching for "new folder create".Now, you are ready.
Practice
Let's go back to the console and type the following commandread.csv("C:/R_data/d41ca.csv")
Your computer loaded it properly!
It should look like this |
Now try the following command
setwd("C:/R_data")
read.csv("d41ca.csv")
Did you notice the difference? Yes, we are doing the same thing, but the information passed to "read.csv" is shortened from "C: /R_data/d41ca.csv" to "d41ca.csv".
This is because the working directory was specified with the command "setwd" (set working directory). Open the editor, write your favorite command, and press the save button (you can also save it with Ctrl + S). You will see a screen like this, then please pay attention to the save destination!
It is going to be saved in C (D in my case): / R_data.
By specifying the working directory like this, you can save the trouble of clicking many times for selecting the save destination, and you can use a shorter sentence when reading the file.
In the current example, the amount of writing has increased, but when you want to read some files, for example,
read.csv("C:/aaa/bbb/ccc/aiueo.csv")
read.csv("C:/aaa/bbb/ccc/kakikukeko.csv")
read.csv("C:/aaa/bbb/ccc/sasisuseso.csv")
read.csv("C:/aaa/bbb/ccc/tatituteto.csv")
this become
setwd("C:/aaa/bbb/ccc")
read.csv("aiueo.csv")
read.csv("kakikukeko.csv")
read.csv("sasisuseso.csv")
read.csv("tatituteto.csv")
It's organized and easy to see.
Now do you understand the usefulness of working directory?
After a short break, next is the last content!
Experiment with data types
First, you don't know what the type is, so try the following commandmode(c(1,1))
mode("program")
I think the above command returned "numeric", and the lower command returned "character". Here, "mode" is a command that returns the type of the object. An object is created by a command, and the result (object) output by "read.csv" above also has a type. Let's check it out.
mode(read.csv("d41ca.csv"))
I think the list has returned. Thus, each object has a type. Why have a type? You can get it by typing the following command.
1+2
"1"+"2"
mode(1)
mode("1")
I think there was an error in the second line. Since + can only be calculated between "numeric", an error is immediately generated. Because of the type, the computer is not confused even if "character" etc. is mistakenly included in the calculation formula.
Sometimes, however, it is difficult to achieve the desired result due to the type. I wrote a command example below. This can be ignored.
# Goal: I want to divide 1979 by 10 (1979 is fourth element in column 1 of data)
data <- read.csv("d41ca.csv")
mode(data) # Basically, use [[]] to access list
data[[1]][4] # extract fourth element in the first (first column) of data
data[4,1] # You can also extract data by writing 4 rows and 1 column of data, you can extract the entire first column with data[, 1]
# use data[4,1] because it's easier
mode(data[4,1]) # Numeric, so it’s likely to divide by 10
data[4,1]/10 # Can’t divide… In this case, it would be factor
as.numeric(data[4,1]) # “as.numeric” is a command to change the type to numeric. But it will be 2
as.numeric(as.character(data[4,1])) # yippee!
as.numeric(as.character(data[4,1])) / 10 # GOAL accomplished!
This is the end of the Part 3.
if you have a command you need or interesting in this article, write a comment in the editor and save it. If you save the file with a descriptive name, it will be easier to find later.
After the important save is completed, return to the screen of R, press "X" on the upper right, select "No" in "Save workspace?", And R will be finished safely. Good work!
If you like it, please feel free to advertise on social media, etc. ... Since I wrote it, I really want to see as many people as possible lol.
Thank you for your reading! See you again!
Appendix:
This is an example of “nleqslv” mentioned in the article.The first one is
a + b + c = 10
a + b - c = 8
a - b - c = - 4
The second one is
a + b = 1
a² + b² = 13
Let’s use “nleqslv”!
library(nleqslv)
fn2 <- function(x) {
a <- x[1]
b <- x[2]
c <- x[3]
ans <- c()
ans[1] <- a + b + c - 10
ans[2] <- a + b - c - 8
ans[3] <- a - b - c + 4
return(ans)
}
nleqslv(c(1, 1, 1), fn2)
fn3 <- function(x) {
a <- x[1]
b <- x[2]
ans <- c()
ans[1] <- a + b - 1
ans[2] <- a^2 + b^2 - 13
return(ans)
}
nleqslv(c(1, -1), fn3) # c(1, 1) don’t work
Comments
Post a Comment